Exemple #1
0
def run(args):
    if args not in (["--with-quotes"], ["--no-quotes"]):
        sys.exit("fable.fem_include_search_paths --with-quotes|--no-quotes")
    comp_env = simple_compilation.environment()
    print(
        comp_env.assemble_include_search_paths(
            no_quotes=(args[0] == "--no-quotes")))
Exemple #2
0
def run(args):
  if (args not in [["--with-quotes"], ["--no-quotes"]]):
    from libtbx.utils import Usage
    import libtbx.load_env
    raise Usage("%s --with-quotes|--no-quotes" % libtbx.env.dispatcher_name)
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  print(comp_env.assemble_include_search_paths(
    no_quotes=(args[0]=="--no-quotes")))
def run(args):
  if (args not in [["--with-quotes"], ["--no-quotes"]]):
    from libtbx.utils import Usage
    import libtbx.load_env
    raise Usage("%s --with-quotes|--no-quotes" % libtbx.env.dispatcher_name)
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  print comp_env.assemble_include_search_paths(
    no_quotes=(args[0]=="--no-quotes"))
Exemple #4
0
def build_cmds(tst_f):
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  exe = comp_env.exe_suffix
  result = []
  remove_file("fable_cout")
  cmd = "fable.cout %s --link" % tst_f
  easy_run.fully_buffered(command=cmd).raise_if_errors()
  assert os.path.exists("fable_cout"+exe)
  result.append("fable_cout"+exe)
  return [os.path.join(".", cmd) for cmd in result]
def exercise(verbose,
             file_names_cpp,
             number_of_function_files=None,
             separate_files_main_namespace={},
             separate_files_separate_namespace={}):
    if (verbose): print("next exercise")
    import libtbx.load_env
    test_valid = libtbx.env.under_dist(module_name="fable",
                                       path="test/valid",
                                       test=op.isdir)
    import fable.cout
    top_cpp = fable.cout.process(
        file_names=[op.join(test_valid, "subroutine_3.f")],
        top_procedures=["prog"],
        namespace="tst_separate_files",
        top_cpp_file_name=file_names_cpp[0],
        number_of_function_files=number_of_function_files,
        separate_files_main_namespace=separate_files_main_namespace,
        separate_files_separate_namespace=separate_files_separate_namespace)
    from fable import simple_compilation
    comp_env = simple_compilation.environment()
    from libtbx import easy_run
    file_names_obj = []
    for file_name_cpp in file_names_cpp:
        obj = comp_env.file_name_obj(file_name_cpp=file_name_cpp)
        remove_file_if_necessary(file_name=obj)
        cmd = comp_env.compilation_command(file_name_cpp=file_name_cpp)
        if (verbose): print(cmd)
        easy_run.call(command=cmd)
        assert op.exists(obj)
        file_names_obj.append(obj)
    exe_root = "tst_separate_files"
    exe = comp_env.file_name_exe(exe_root=exe_root)
    remove_file_if_necessary(file_name=exe)
    cmd = comp_env.link_command(file_names_obj=file_names_obj,
                                exe_root=exe_root)
    if (verbose): print(cmd)
    easy_run.call(command=cmd)
    cmd = op.join(".", exe)
    if (verbose): print(cmd)
    assert op.exists(cmd)
    stdout = easy_run.fully_buffered(
        command=cmd).raise_if_errors().stdout_lines
    text = "\n".join(stdout)
    if (verbose):
        print(text)
    from fable.tst_cout_compile import read_file_names_and_expected_cout
    info = read_file_names_and_expected_cout(
        test_valid=test_valid).get("subroutine_3.f")[0]
    from libtbx.test_utils import show_diff
    assert not show_diff(text, "\n".join(info.out_lines))
    if (verbose): print()
def exercise(
      verbose,
      file_names_cpp,
      number_of_function_files=None,
      separate_files_main_namespace={},
      separate_files_separate_namespace={}):
  if (verbose): print "next exercise"
  import libtbx.load_env
  test_valid = libtbx.env.under_dist(
    module_name="fable", path="test/valid", test=op.isdir)
  import fable.cout
  top_cpp = fable.cout.process(
    file_names=[op.join(test_valid, "subroutine_3.f")],
    top_procedures=["prog"],
    namespace="tst_separate_files",
    top_cpp_file_name=file_names_cpp[0],
    number_of_function_files=number_of_function_files,
    separate_files_main_namespace=separate_files_main_namespace,
    separate_files_separate_namespace=separate_files_separate_namespace)
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  from libtbx import easy_run
  file_names_obj = []
  for file_name_cpp in file_names_cpp:
    obj = comp_env.file_name_obj(file_name_cpp=file_name_cpp)
    remove_file_if_necessary(file_name=obj)
    cmd = comp_env.compilation_command(file_name_cpp=file_name_cpp)
    if (verbose): print cmd
    easy_run.call(command=cmd)
    assert op.exists(obj)
    file_names_obj.append(obj)
  exe_root = "tst_separate_files"
  exe = comp_env.file_name_exe(exe_root=exe_root)
  remove_file_if_necessary(file_name=exe)
  cmd = comp_env.link_command(file_names_obj=file_names_obj, exe_root=exe_root)
  if (verbose): print cmd
  easy_run.call(command=cmd)
  cmd = op.join(".", exe)
  if (verbose): print cmd
  assert op.exists(cmd)
  stdout = easy_run.fully_buffered(command=cmd).raise_if_errors().stdout_lines
  text = "\n".join(stdout)
  if (verbose):
    print text
  from fable.tst_cout_compile import read_file_names_and_expected_cout
  info = read_file_names_and_expected_cout(test_valid=test_valid).get(
    "subroutine_3.f")[0]
  from libtbx.test_utils import show_diff
  assert not show_diff(text, "\n".join(info.out_lines))
  if (verbose): print
def build_cmds(tst_f, opts, ignore_ifort=False):
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  exe = comp_env.exe_suffix
  result = []
  if (opts.ifort and not ignore_ifort):
    remove_file("a.out")
    cmd = "ifort -diag-disable 7951 %s" % tst_f
    if (opts.verbose): print cmd
    easy_run.fully_buffered(command=cmd).raise_if_errors()
    assert op.exists("a.out")
    result.append("a.out")
  remove_file("fable_cout")
  cmd = "fable.cout %s --link" % tst_f
  if (opts.verbose): print cmd
  easy_run.fully_buffered(command=cmd).raise_if_errors()
  assert op.exists("fable_cout"+exe)
  result.append("fable_cout"+exe)
  return [op.join(".", cmd) for cmd in result]
Exemple #8
0
def build_cmds(tst_f, opts, ignore_ifort=False):
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  exe = comp_env.exe_suffix
  result = []
  if (opts.ifort and not ignore_ifort):
    remove_file("a.out")
    cmd = "ifort -diag-disable 7951 %s" % tst_f
    if (opts.verbose): print cmd
    easy_run.fully_buffered(command=cmd).raise_if_errors()
    assert op.exists("a.out")
    result.append("a.out")
  remove_file("fable_cout")
  cmd = "fable.cout %s --link" % tst_f
  if (opts.verbose): print cmd
  easy_run.fully_buffered(command=cmd).raise_if_errors()
  assert op.exists("fable_cout"+exe)
  result.append("fable_cout"+exe)
  return [op.join(".", cmd) for cmd in result]
def exercise_compile_valid(regex_patterns, opts):
  from fable import cout
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  if (comp_env.compiler_path is None):
    print "Skipping exercise_compile_valid(): %s not available." % \
      comp_env.compiler
    return
  import libtbx.load_env
  import os.path as op
  fable_dist = libtbx.env.dist_path(module_name="fable")
  test_valid = op.join(fable_dist, "test/valid")
  selected_file_names_and_expected_cout = regex_select(
    keyed_lists=read_file_names_and_expected_cout(test_valid=test_valid),
    regex_patterns=regex_patterns)
  assert len(selected_file_names_and_expected_cout) != 0
  #
  if (opts.pch):
    comp_env.build(
      link=False,
      file_name_cpp=op.join(fable_dist, "fem.hpp"),
      pch_name="fem.hpp",
      show_command=True)
    comp_env.set_have_pch()
    print
  #
  processor = process_file_info(
    opts=opts, comp_env=comp_env, test_valid=test_valid)
  #
  if (not opts.multiprocessing):
    n_failures = 0
    for file_info in selected_file_names_and_expected_cout:
      n_failures += processor(file_info=file_info)
    return n_failures
  #
  n_proc = min(
    len(selected_file_names_and_expected_cout),
    opts.max_proc)
  print "Number of processors:", n_proc
  import multiprocessing
  mp_pool = multiprocessing.Pool(processes=n_proc)
  return sum(mp_pool.map(processor, selected_file_names_and_expected_cout))
Exemple #10
0
 def __call__(O, file_names):
     import sys
     if (O.n_calls != 0):
         print
     O.n_calls += 1
     opts = O.options
     lines = fable.cout.process(
         file_names=file_names,
         top_procedures=opts.top_procedure,
         include_guard_suffix=opts.include_guard_suffix,
         dynamic_parameters=O.dynamic_parameters,
         fortran_file_comments=opts.fortran_file_comments,
         fem_do_safe=not opts.no_fem_do_safe,
         arr_nd_size_max=opts.arr_nd_size_max,
         inline_all=opts.inline_all,
         common_equivalence_simple=set(
             opts.common_equivalence_simple.split(",")),
         namespace=opts.namespace,
         separate_cmn_hpp=opts.separate_cmn_hpp,
         number_of_function_files=opts.number_of_function_files,
         debug=opts.debug)
     text = "\n".join(lines) + "\n"
     if (opts.top_procedure is None or not opts.debug):
         sys.stdout.write(text)
     if (len(file_names) != 0 and opts.compile):
         print
         write_only_if_safe(file_name="fable_cout.cpp", text=text)
         from fable import simple_compilation
         comp_env = simple_compilation.environment()
         out_name = comp_env.build(link=opts.link,
                                   file_name_cpp="fable_cout.cpp",
                                   show_command=True)
         print
         if (opts.run):
             from libtbx import easy_run
             import os
             op = os.path
             cmd = op.join(".", out_name)
             if (opts.valgrind):
                 cmd = "valgrind " + cmd
             print cmd
             easy_run.call(command=cmd)
Exemple #11
0
 def __call__(self,tst_f, opts, ignore_ifort=False):
  self.iteration += 1
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  exe = comp_env.exe_suffix
  result = []
  if (opts.ifort and not ignore_ifort):
    remove_file("a.out")
    cmd = "ifort -diag-disable 7951 %s" % tst_f
    if (opts.verbose): print(cmd)
    easy_run.fully_buffered(command=cmd).raise_if_errors()
    assert op.exists("a.out")
    result.append("a.out")
  #remove_file("fable_cout")
  cmd = "fable.cout %s --link --exe_name=fable_cout%02d" %(tst_f,self.iteration)
  if (opts.verbose): print(cmd)
  easy_run.fully_buffered(command=cmd).raise_if_errors()
  assert op.exists("fable_cout%02d"%self.iteration+exe)
  result.append("fable_cout%02d"%self.iteration+exe)
  return [op.join(".", cmd) for cmd in result]
Exemple #12
0
def exercise_compile_valid(regex_patterns, opts):
    from fable import cout
    from fable import simple_compilation
    comp_env = simple_compilation.environment()
    if (comp_env.compiler_path is None):
        print "Skipping exercise_compile_valid(): %s not available." % \
          comp_env.compiler
        return
    import libtbx.load_env
    import os.path as op
    fable_dist = libtbx.env.dist_path(module_name="fable")
    test_valid = op.join(fable_dist, "test/valid")
    selected_file_names_and_expected_cout = regex_select(
        keyed_lists=read_file_names_and_expected_cout(test_valid=test_valid),
        regex_patterns=regex_patterns)
    assert len(selected_file_names_and_expected_cout) != 0
    #
    if (opts.pch):
        comp_env.build(link=False,
                       file_name_cpp=op.join(fable_dist, "fem.hpp"),
                       pch_name="fem.hpp",
                       show_command=True)
        comp_env.set_have_pch()
        print
    #
    processor = process_file_info(opts=opts,
                                  comp_env=comp_env,
                                  test_valid=test_valid)
    #
    if (not opts.multiprocessing):
        n_failures = 0
        for file_info in selected_file_names_and_expected_cout:
            n_failures += processor(file_info=file_info)
        return n_failures
    #
    n_proc = min(len(selected_file_names_and_expected_cout), opts.max_proc)
    print "Number of processors:", n_proc
    import multiprocessing
    mp_pool = multiprocessing.Pool(processes=n_proc)
    return sum(mp_pool.map(processor, selected_file_names_and_expected_cout))
Exemple #13
0
 def __call__(O, file_names):
   import sys
   if (O.n_calls != 0):
     print
   O.n_calls += 1
   opts = O.options
   lines = fable.cout.process(
     file_names=file_names,
     top_procedures=opts.top_procedure,
     include_guard_suffix=opts.include_guard_suffix,
     dynamic_parameters=O.dynamic_parameters,
     fortran_file_comments=opts.fortran_file_comments,
     fem_do_safe=not opts.no_fem_do_safe,
     arr_nd_size_max=opts.arr_nd_size_max,
     inline_all=opts.inline_all,
     common_equivalence_simple=set(opts.common_equivalence_simple.split(",")),
     namespace=opts.namespace,
     separate_cmn_hpp=opts.separate_cmn_hpp,
     number_of_function_files=opts.number_of_function_files,
     debug=opts.debug)
   text = "\n".join(lines)+"\n"
   if (opts.top_procedure is None or not opts.debug):
     sys.stdout.write(text)
   if (len(file_names) != 0 and opts.compile):
     print
     write_only_if_safe(file_name="fable_cout.cpp", text=text)
     from fable import simple_compilation
     comp_env = simple_compilation.environment()
     out_name = comp_env.build(
       link=opts.link, file_name_cpp="fable_cout.cpp", show_command=True)
     print
     if (opts.run):
       from libtbx import easy_run
       import os
       op = os.path
       cmd = op.join(".", out_name)
       if (opts.valgrind):
         cmd = "valgrind " + cmd
       print cmd
       easy_run.call(command=cmd)
Exemple #14
0
def finalize_cpp_build_cmd(source_cpp):
    from fable import simple_compilation
    comp_env = simple_compilation.environment()
    return comp_env.assemble_include_search_paths(no_quotes=False) \
      + " " + source_cpp
def finalize_cpp_build_cmd(source_cpp):
  from fable import simple_compilation
  comp_env = simple_compilation.environment()
  return comp_env.assemble_include_search_paths(no_quotes=False) \
    + " " + source_cpp