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