Commit 3b10299a authored by Nicolas Chevillot's avatar Nicolas Chevillot

(feat-1176) Only one call to os.getcwd(), stored in global module.

parent 9d303eea
......@@ -46,13 +46,15 @@ from action import (CheckCondition, CleanModules, FetchModules, GenerateFetchMak
def main():
"""This is the main funcion, where HDLMake starts.
"""This is the main function, where HDLMake starts.
Here, we make the next processes:
-- parse command
-- check and set the environment
-- prepare the global module containing the heavy common stuff
"""
"""
# Remember current path
global_mod.current_path = os.getcwd()
#
# SET & GET PARSER
......@@ -80,7 +82,7 @@ def main():
modules_pool = ModulePool()
modules_pool.new_module(parent=None,
url=os.getcwd(),
url=global_mod.current_path,
source=fetch_mod.LOCAL,
fetchto=".",
process_manifest=False)
......
......@@ -28,7 +28,7 @@ import os
import os.path
import time
import sys
import global_mod
class MergeCores(Action):
def _check_manifest(self):
......@@ -100,6 +100,6 @@ class MergeCores(Action):
for ngc in flist.filter(NGCFile):
import shutil
logging.info("copying NGC file: %s" % ngc.rel_path())
shutil.copy(ngc.rel_path(), os.getcwd())
shutil.copy(ngc.rel_path(), global_mod.current_path)
logging.info("Cores merged.")
\ No newline at end of file
......@@ -27,8 +27,6 @@ import sys
import global_mod
from srcfile import SourceFileFactory
import importlib
class GenerateRemoteSynthesisMakefile(Action):
......@@ -91,7 +89,7 @@ class GenerateRemoteSynthesisMakefile(Action):
files.add(sff.new(top_mod.syn_project, module=None))
tool_object.generate_remote_synthesis_makefile(files=files, name=top_mod.syn_name,
cwd=os.getcwd(), user=self.env["rsynth_user"],
cwd=global_mod.current_path, user=self.env["rsynth_user"],
server=self.env["rsynth_server"])
logging.info("Remote synthesis makefile generated.")
......
......@@ -98,7 +98,7 @@ class File(object):
def rel_path(self, dir=None):
if dir is None:
dir = os.getcwd()
dir = global_mod.current_path
return path_mod.relpath(self.path, dir)
def __str__(self):
......
......@@ -107,7 +107,7 @@ class VerilogDependencySolver(DependencySolver):
inc_dirs = self._parse_vlog_opt(v_file.vlog_opt)
for dir in inc_dirs:
dir = os.path.join(os.getcwd(), dir)
dir = os.path.join(global_mod.current_path, dir)
if not os.path.exists(dir) or not os.path.isdir(dir):
logging.warning("Include path "+dir+" doesn't exist")
continue
......
......@@ -26,13 +26,14 @@ from tempfile import TemporaryFile
from subprocess import Popen, PIPE
import fetch
from fetcher import Fetcher
import global_mod
class GitSubmodule(Fetcher):
def fetch(self, module):
if module.source != fetch.GITSUBMODULE:
raise ValueError("This backend should get git modules only.")
cur_dir = os.getcwd()
cur_dir = global_mod.current_path
os.chdir(module.fetchto)
os.system("git submodule init")
os.system("git submodule update")
......@@ -45,7 +46,7 @@ class Git(Fetcher):
@staticmethod
def get_git_toplevel(module):
cur_dir = os.getcwd()
cur_dir = global_mod.current_path
try:
os.chdir(path.rel2abs(module.path))
if not os.path.exists(".gitmodules"):
......@@ -63,7 +64,7 @@ class Git(Fetcher):
def get_git_submodules(module):
submodule_dir = path.rel2abs(module.path)
logging.debug("Checking git submodules in %s" % submodule_dir)
cur_dir = os.getcwd()
cur_dir = global_mod.current_path
try:
os.chdir(submodule_dir)
......@@ -117,7 +118,7 @@ submodule.ip_cores/wr-cores.url=git://ohwr.org/hdl-core-lib/wr-cores.git
if not os.path.exists(module.fetchto):
os.mkdir(module.fetchto)
cur_dir = os.getcwd()
cur_dir = global_mod.current_path
if module.branch is None:
module.branch = "master"
......@@ -164,7 +165,7 @@ submodule.ip_cores/wr-cores.url=git://ohwr.org/hdl-core-lib/wr-cores.git
@staticmethod
def check_commit_id(path):
cur_dir = os.getcwd()
cur_dir = global_mod.current_path
commit = None
stderr = TemporaryFile()
try:
......
......@@ -25,6 +25,7 @@ from tempfile import TemporaryFile
from util import path
from subprocess import Popen, PIPE
from fetcher import Fetcher
import global_mod
class Svn(Fetcher):
......@@ -35,7 +36,7 @@ class Svn(Fetcher):
if not os.path.exists(module.fetchto):
os.mkdir(module.fetchto)
cur_dir = os.getcwd()
cur_dir = global_mod.current_path
os.chdir(module.fetchto)
basename = path.url_basename(module.url)
......@@ -61,7 +62,7 @@ class Svn(Fetcher):
@staticmethod
def check_revision_number(path):
cur_dir = os.getcwd()
cur_dir = global_mod.current_path
revision = None
stderr = TemporaryFile()
......
......@@ -29,4 +29,4 @@ mod_pool = None
sim_tool = None
env = None
tool_module = None
current_path = None
......@@ -113,7 +113,7 @@ class ModulePool(list):
def _guess_origin(self, path):
"""Guess origin (git, svn, local) of a module at given path"""
cwd = os.getcwd()
cwd = global_mod.current_path
try:
os.chdir(path)
git_out = Popen("git config --get remote.origin.url", stdout=PIPE, shell=True, close_fds=True)
......
......@@ -23,6 +23,7 @@
from __future__ import print_function
import os
import logging
import global_mod
def url_parse(url):
......@@ -114,7 +115,7 @@ def is_abs_path(path):
def relpath(p1, p2=None):
if p2 is None:
p2 = os.getcwd()
p2 = global_mod.current_path
if p1 == p2:
return '.'
p1, p2 = p2, p1
......@@ -142,7 +143,7 @@ def rel2abs(path, base=None):
@return the relative path of path from base
"""
if base is None:
base = os.getcwd()
base = global_mod.current_path
if os.path.isabs(path):
return path
retval = os.path.join(base, path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment