Skip to content

Commit

Permalink
Remove profile build, simplify build.py
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianPommerening committed Jul 26, 2023
1 parent 232503a commit 6da0b21
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 76 deletions.
74 changes: 22 additions & 52 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

import errno
import multiprocessing
import os
import subprocess
import sys
Expand All @@ -12,24 +11,9 @@
if not config.startswith("_")}
DEFAULT_CONFIG_NAME = CONFIGS.pop("DEFAULT")
DEBUG_CONFIG_NAME = CONFIGS.pop("DEBUG")

CMAKE = "cmake"
DEFAULT_MAKE_PARAMETERS = []
if os.name == "posix":
MAKE = "make"
try:
num_cpus = multiprocessing.cpu_count()
except NotImplementedError:
pass
else:
DEFAULT_MAKE_PARAMETERS.append('-j{}'.format(num_cpus))
CMAKE_GENERATOR = "Unix Makefiles"
elif os.name == "nt":
MAKE = "nmake"
CMAKE_GENERATOR = "NMake Makefiles"
else:
print("Unsupported OS: " + os.name)
sys.exit(1)
# Number of usable CPUs (see https://docs.python.org/3/library/os.html)
NUM_CPUS = len(os.sched_getaffinity(0))


def print_usage():
Expand All @@ -43,18 +27,14 @@ def print_usage():
configs.append(name + "\n " + " ".join(args))
configs_string = "\n ".join(configs)
cmake_name = os.path.basename(CMAKE)
make_name = os.path.basename(MAKE)
generator_name = CMAKE_GENERATOR.lower()
default_config_name = DEFAULT_CONFIG_NAME
debug_config_name = DEBUG_CONFIG_NAME
print("""Usage: {script_name} [BUILD [BUILD ...]] [--all] [--debug] [MAKE_OPTIONS]
print(f"""Usage: {script_name} [BUILD [BUILD ...]] [--all] [--debug] [MAKE_OPTIONS]
Build one or more predefined build configurations of Fast Downward. Each build
uses {cmake_name} to generate {generator_name} and then uses {make_name} to compile the
code. Build configurations differ in the parameters they pass to {cmake_name}.
By default, the build uses N threads on a machine with N cores if the number of
cores can be determined. Use the "-j" option for {cmake_name} to override this default
behaviour.
uses {cmake_name} compile the code. Build configurations differ in the
parameters they pass to {cmake_name}. By default, the build uses all available cores.
Use the "-j" option for {cmake_name} to override this default behaviour.
Build configurations
{configs_string}
Expand All @@ -64,7 +44,7 @@ def print_usage():
--help Print this message and exit.
Make options
All other parameters are forwarded to {make_name}.
All other parameters are forwarded to the build step.
Example usage:
./{script_name} # build {default_config_name} in #cores threads
Expand All @@ -73,7 +53,7 @@ def print_usage():
./{script_name} --debug # build {debug_config_name}
./{script_name} release debug # build release and debug configs
./{script_name} --all VERBOSE=true # build all build configs with detailed logs
""".format(**locals()))
""")


def get_project_root_path():
Expand All @@ -92,41 +72,31 @@ def get_src_path():
def get_build_path(config_name):
return os.path.join(get_builds_path(), config_name)

def try_run(cmd, cwd):
print('Executing command "{}" in directory "{}".'.format(" ".join(cmd), cwd))
def try_run(cmd):
print(f'Executing command "{" ".join(cmd)}"')
try:
subprocess.check_call(cmd, cwd=cwd)
subprocess.check_call(cmd)
except OSError as exc:
if exc.errno == errno.ENOENT:
print("Could not find '%s' on your PATH. For installation instructions, "
"see https://www.fast-downward.org/ObtainingAndRunningFastDownward." %
cmd[0])
print(f"Could not find '{cmd[0]}' on your PATH. For installation instructions, "
"see https://www.fast-downward.org/ObtainingAndRunningFastDownward.")
sys.exit(1)
else:
raise

def build(config_name, cmake_parameters, make_parameters):
print("Building configuration {config_name}.".format(**locals()))
build_path = get_build_path(config_name)
rel_src_path = os.path.relpath(get_src_path(), build_path)
try:
os.makedirs(build_path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(build_path):
pass
else:
raise
def build(config_name, configure_parameters, build_parameters):
print(f"Building configuration {config_name}.")

try_run([CMAKE, "-G", CMAKE_GENERATOR] + cmake_parameters + [rel_src_path],
cwd=build_path)
try_run([MAKE] + make_parameters, cwd=build_path)
build_path = get_build_path(config_name)
try_run([CMAKE, "-S", get_src_path(), "-B", build_path] + configure_parameters)
try_run([CMAKE, "--build", build_path, "-j", f"{NUM_CPUS}", "--"] + build_parameters)

print("Built configuration {config_name} successfully.".format(**locals()))
print(f"Built configuration {config_name} successfully.")


def main():
config_names = set()
make_parameters = DEFAULT_MAKE_PARAMETERS
build_parameters = []
for arg in sys.argv[1:]:
if arg == "--help" or arg == "-h":
print_usage()
Expand All @@ -138,11 +108,11 @@ def main():
elif arg in CONFIGS:
config_names.add(arg)
else:
make_parameters.append(arg)
build_parameters.append(arg)
if not config_names:
config_names.add(DEFAULT_CONFIG_NAME)
for config_name in config_names:
build(config_name, CONFIGS[config_name], make_parameters)
build(config_name, CONFIGS[config_name], build_parameters)


if __name__ == "__main__":
Expand Down
15 changes: 5 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# Usage:
# mkdir -p builds/release
# cd builds/release
# cmake path/to/src
# make [-j4]
# The call to cmake caches settings in the build directory and reads
# cmake -S src -B builds/release
# cmake --build builds/release
# The first call caches settings in the build directory and reads
# them from the cache on subsequent builds. If you want to change the
# settings of some options, do _not_ change the CMakeLIsts.txt files.
# settings of some options, do _not_ change the CMakeLists.txt files.
# Instead, create a new build directory, pass -DMY_OPTION=my_value to
# cmake. Alternatively, you can use a cmake GUI like ccmake to edit
# the cache.
#
# Three build targets are defined:
# Two build targets are defined:
#
# * release (default)
# -O3 optimisation, debugging symbols, assertions inactive
# * debug
# -O3 optimisation, full debugging information, assertions active
# * profile
# like Debug but with profile information linked in
#
# In all build targets, we overwrite the default configuration to
# include "-g", allow cross compilation and switch to pedantic error
Expand Down Expand Up @@ -45,7 +41,6 @@ fast_downward_report_bitwidth()
# Due to a bug in cmake, configuration types are only set up correctly on the second cmake run.
# This means that cmake has to be called twice for multi-config generators like Visual Studio.
fast_downward_set_configuration_types()
fast_downward_add_profile_build()

set(FAST_DOWNWARD_MAIN_CMAKELISTS_READ TRUE)

Expand Down
15 changes: 1 addition & 14 deletions src/cmake_modules/FastDownwardMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ macro(fast_downward_set_compiler_flags)
if(USE_GLIBCXX_DEBUG)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
endif()
set(CMAKE_CXX_FLAGS_PROFILE "-O3 -pg")
elseif(MSVC)
check_and_set_compiler_flag( "/std:c++20" )

Expand Down Expand Up @@ -67,18 +66,6 @@ macro(fast_downward_set_linker_flags)
endif()
endmacro()

macro(fast_downward_add_profile_build)
# We don't offer a dedicated PROFILE build on Windows.
if(CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
if(NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY HELPSTRING "Choose the type of build")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;Profile")
endif()
set(CMAKE_CXX_FLAGS_PROFILE ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -pg")
endif()
endmacro()

macro(fast_downward_default_to_release_build)
# Only for single-config generators (like Makefiles) that choose the build type at generation time.
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
Expand All @@ -91,7 +78,7 @@ macro(fast_downward_set_configuration_types)
# Only for multi-config generators (like Visual Studio Projects) that choose
# the build type at build time.
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Profile"
set(CMAKE_CONFIGURATION_TYPES "Debug;Release"
CACHE STRING "Reset the configurations to what we need" FORCE)
endif()
endmacro()
Expand Down

0 comments on commit 6da0b21

Please sign in to comment.