Ejemplo n.º 1
0
def test_no_isysroot(tmpdir):
    c = Clade(tmpdir)

    opts = ["-I/usr/include"]

    filtered_opts = filter_opts(opts, c.get_storage_path)

    assert len(filtered_opts) == len(opts)
    assert filtered_opts[0] == "-I{}/usr/include".format(c.storage_dir)
Ejemplo n.º 2
0
def prepare_cif_opts(opts, clade, model_opts=False):
    new_opts = []
    meta = clade.get_meta()

    # Keep model options as well as build options when input files were not preprocessed.
    if model_opts or not meta['conf'].get("Compiler.preprocess_cmds", False):
        new_opts = filter_opts(opts, clade.get_storage_path)
        new_opts = [opt.replace('"', '\\"') for opt in new_opts]

    extra_cc_opts = meta['conf'].get('Info.extra_CIF_opts', list())
    new_opts.extend(extra_cc_opts)

    return new_opts
Ejemplo n.º 3
0
def test_bad_opt():
    opts = ["-ABC", "-Dtest"]

    assert filter_opts(opts) == ["-Dtest"]
Ejemplo n.º 4
0
def test_no_get_storage_path():
    opts = ["-I/usr/include"]

    assert filter_opts(opts) == opts
Ejemplo n.º 5
0
Archivo: info.py Proyecto: 17451k/clade
    def _run_cif(self, cmd):
        if self.__is_cmd_bad_for_cif(cmd):
            return

        tmp_dir = os.path.join(self.temp_dir, str(os.getpid()))
        os.makedirs(tmp_dir, exist_ok=True)

        # If True then  CIF will be executed on preprocessed .i file
        use_pre = self.conf.get("Compiler.preprocess_cmds") and self.conf.get(
            "Info.use_preprocessed_files")

        for cmd_in in cmd["in"]:
            storage_cmd_in = self.extensions["Storage"].get_storage_path(
                cmd_in)

            if use_pre:
                cif_in = self.extensions[cmd["type"]].get_pre_file_by_path(
                    cmd_in, cmd["cwd"])
            else:
                cif_in = storage_cmd_in

            if not os.path.exists(cif_in):
                continue

            cif_out = os.path.join(
                tmp_dir,
                os.path.basename(storage_cmd_in.lstrip(os.sep)) + ".o")

            cif_env = {"CIF_INFO_DIR": self.cif_output_dir, "C_FILE": cmd_in}

            cif_args = [
                self.conf.get("Info.cif", "cif"), "--debug", "ALL", "--in",
                cif_in, "--aspect", self.aspect, "--back-end", "src",
                "--stage", "instrumentation", "--out", cif_out
            ]

            if self.conf.get("Info.aspectator"):
                cif_args.extend(
                    ["--aspectator",
                     self.conf.get("Info.aspectator")])

            if use_pre:
                opts = []
            else:
                opts = self.extensions[cmd["type"]].load_opts_by_id(cmd["id"])
                opts = filter_opts(opts,
                                   self.extensions["Storage"].get_storage_path)

            opts.extend(self.conf.get("Info.extra_CIF_opts", []))
            opts = [re.sub(r"\"", r'\\"', opt) for opt in opts]

            if opts:
                cif_args.append("--")
                cif_args.extend(opts)

            cwd = self.extensions["Storage"].get_storage_path(cmd["cwd"])
            os.makedirs(cwd, exist_ok=True)

            # env is for subprocess
            env = os.environ.copy()
            env.update(cif_env)

            try:
                output = subprocess.check_output(cif_args,
                                                 stderr=subprocess.STDOUT,
                                                 cwd=cwd,
                                                 universal_newlines=True,
                                                 env=env)
                self.__save_log(cmd["id"], cwd, cif_args, cif_env, output,
                                self.cif_log)
            except subprocess.CalledProcessError as e:
                self.__save_log(cmd["id"], cwd, cif_args, cif_env, e.output,
                                self.err_log)
                self.__save_log(cmd["id"], cwd, cif_args, cif_env, e.output,
                                self.cif_log)
                return
            except UnicodeDecodeError as e:
                self.warning(
                    "Can't decode CIF console output using 'utf-8' codec for command {!r}"
                    .format(cmd["id"]))

                self.__save_log(cmd["id"], cwd, cif_args, cif_env, str(e),
                                self.err_log)
                self.__save_log(cmd["id"], cwd, cif_args, cif_env, str(e),
                                self.cif_log)

        # Force garbage collector to work
        gc.collect()