Skip to content

Commit

Permalink
toolchain: fix shared install dirs (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre authored Mar 4, 2024
1 parent 605ee69 commit cf4ca8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions toolchain/mfc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ def compute(self) -> typing.Set:
def __hash__(self) -> int:
return hash(self.name)

# Get path to directory that will store the build files
def get_build_dirpath(self) -> str:
def get_slug(self) -> str:
if self.isDependency:
slug = self.name
else:
slug = f"{CFG().make_slug()}-{self.name}"
return self.name

if ARG("case_optimization"):
m = hashlib.sha256()
m.update(input.load().get_fpp(self).encode())
m = hashlib.sha256()
m.update(self.name.encode())
m.update(CFG().make_slug().encode())
m.update(input.load({}).get_fpp(self).encode())

slug = f"{slug}-{m.hexdigest()[:6]}"
return m.hexdigest()[:10]

return os.sep.join([os.getcwd(), "build", slug ])
# Get path to directory that will store the build files
def get_staging_dirpath(self) -> str:
return os.sep.join([os.getcwd(), "build", "staging", self.get_slug() ])

# Get the directory that contains the target's CMakeLists.txt
def get_cmake_dirpath(self) -> str:
Expand All @@ -58,13 +58,13 @@ def get_cmake_dirpath(self) -> str:

def get_install_dirpath(self) -> str:
# The install directory is located:
# Regular: <root>/build/install/<configuration_slug>
# Regular: <root>/build/install/<slug>
# Dependency: <root>/build/install/dependencies (shared)
return os.sep.join([
os.getcwd(),
"build",
"install",
'dependencies' if self.isDependency else CFG().make_slug()
'dependencies' if self.isDependency else self.get_slug(),
])

def get_install_binpath(self) -> str:
Expand All @@ -75,14 +75,14 @@ def is_configured(self) -> bool:
# We assume that if the CMakeCache.txt file exists, then the target is
# configured. (this isn't perfect, but it's good enough for now)
return os.path.isfile(
os.sep.join([self.get_build_dirpath(), "CMakeCache.txt"])
os.sep.join([self.get_staging_dirpath(), "CMakeCache.txt"])
)

def get_configuration_txt(self) -> typing.Optional[dict]:
if not self.is_configured():
return None

configpath = os.path.join(self.get_build_dirpath(), "configuration.txt")
configpath = os.path.join(self.get_staging_dirpath(), "configuration.txt")
if not os.path.exists(configpath):
return None

Expand All @@ -101,7 +101,7 @@ def is_buildable(self) -> bool:
return True

def configure(self):
build_dirpath = self.get_build_dirpath()
build_dirpath = self.get_staging_dirpath()
cmake_dirpath = self.get_cmake_dirpath()
install_dirpath = self.get_install_dirpath()

Expand Down Expand Up @@ -154,7 +154,7 @@ def configure(self):
def build(self):
input.load({}).generate_fpp(self)

command = ["cmake", "--build", self.get_build_dirpath(),
command = ["cmake", "--build", self.get_staging_dirpath(),
"--target", self.name,
"--parallel", ARG("jobs"),
"--config", 'Debug' if ARG('debug') else 'Release']
Expand All @@ -167,15 +167,15 @@ def build(self):
cons.print(no_indent=True)

def install(self):
command = ["cmake", "--install", self.get_build_dirpath()]
command = ["cmake", "--install", self.get_staging_dirpath()]

if system(command).returncode != 0:
raise MFCException(f"Failed to install the [bold magenta]{self.name}[/bold magenta] target.")

cons.print(no_indent=True)

def clean(self):
build_dirpath = self.get_build_dirpath()
build_dirpath = self.get_staging_dirpath()

if not os.path.isdir(build_dirpath):
return
Expand Down
2 changes: 1 addition & 1 deletion toolchain/mfc/run/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __contents_equal(str_a: str, str_b: str) -> bool:

return lhs == rhs

inc_dir = os.path.join(target.get_build_dirpath(), "include", target.name)
inc_dir = os.path.join(target.get_staging_dirpath(), "include", target.name)
common.create_directory(inc_dir)

fpp_path = os.path.join(inc_dir, "case.fpp")
Expand Down

0 comments on commit cf4ca8f

Please sign in to comment.