Skip to content

Commit

Permalink
fix: test with windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Calbabreaker committed Dec 12, 2024
1 parent 3ddbf14 commit 8f10f21
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
12 changes: 3 additions & 9 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# import files from previous directory
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from yacpm import info
from yacpm import info, exec_shell

tests_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(tests_dir)
Expand All @@ -31,10 +31,6 @@ def symlink(src, dest):
if not os.path.exists(dest):
os.symlink(src, dest)

def exec_shell(cmd):
if os.system(cmd) != 0:
exit(1)

for test_dir in args.tests:
print_text = f"== RUNNING TEST: {test_dir} =="
padding = "=" * len(print_text)
Expand All @@ -58,10 +54,8 @@ def exec_shell(cmd):
symlink(f"{tests_dir}/../yacpm_extended.cmake", f"yacpm_extended.cmake")
symlink(f"{tests_dir}/../yacpm.py", f"yacpm.py")

if not os.path.exists("./Makefile"):
exec_shell("cmake ..")

exec_shell(f"cmake --build . --parallel {multiprocessing.cpu_count()}")
exec_shell(["cmake", ".."], True)
exec_shell(["cmake", "--build",".","--parallel", str(multiprocessing.cpu_count())], True)

if not args.run:
continue
Expand Down
4 changes: 2 additions & 2 deletions tests/test_remote/yacpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"glm": {
"version": "fc8f4bb442b9540969f2f3f351c4960d91bca17a",
"dependents": [
"imgui",
"yacpm_library_test"
"yacpm_library_test",
"imgui"
]
},
"imgui": {
Expand Down
35 changes: 19 additions & 16 deletions yacpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

# Do not touch YACPM_BRANCH or merge conflict will happen
PROJECT_DIR = os.getcwd()
VERBOSE = False

# Utility functions

Expand Down Expand Up @@ -68,17 +69,19 @@ def download_if_missing(path: str, outfile: str) -> bool:
else:
return False

def exec_shell(command: str) -> str:
proc = subprocess.run(command.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def exec_shell(command_args: list[str], verbose = VERBOSE) -> str:
proc = subprocess.run(command_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout = proc.stdout.decode("utf-8")

command_str = ' '.join(command_args)

if verbose:
info(f"> {command}", False)
info(f"> {command_str}", False)
if stdout:
info(stdout, False)

if proc.returncode != 0:
error(f"Failed to run '{command}': \n{proc.stderr.decode('utf-8')}")
error(f"Failed to run '{command_str}': \n{proc.stderr.decode('utf-8')}")

return stdout

Expand Down Expand Up @@ -109,20 +112,20 @@ def parse_package_version(package_version: str) -> str:
git_ref = package_version.replace("+", "")
# Get default branch if no version specifed
if git_ref == "":
result = exec_shell(f"git remote show origin")
result = exec_shell(["git", "remote", "show", "origin"])
git_ref = re.findall("(?<=HEAD branch: ).+", result)[0]

# Fetch repo with least amount of downloading
exec_shell(f"git fetch --depth=1 --filter=blob:none origin {git_ref}")
exec_shell("git sparse-checkout init")
exec_shell("git checkout FETCH_HEAD")
exec_shell(["git", "fetch", "--depth=1", "--filter=blob:none", "origin", git_ref])
exec_shell(["git", "sparse-checkout", "init"])
exec_shell(["git","checkout", "FETCH_HEAD"])

# Don't freeze to commit if version starting with +
if not package_version.startswith("+"):
rev_name = exec_shell("git name-rev HEAD").strip()
rev_name = exec_shell(["git", "name-rev", "HEAD"]).strip()
# Version is a branch then convert to commit
if not rev_name.endswith("undefined"):
package_version = exec_shell("git rev-parse HEAD").strip()
package_version = exec_shell(["git", "rev-parse", "HEAD"]).strip()
# Don't set default branch if it's ++
elif package_version != "++":
package_version = "+" + git_ref
Expand Down Expand Up @@ -173,13 +176,13 @@ def generate_cmake_variables(package_info: dict) -> str:
# Calc sparse checkout list and download the neccessery package files
def download_package_files(yacpkg: dict, package_info: Union[dict, str], progress_print: str):
# Get lists of includes from the yacpm.json package declaration and yacpkg.json package config and combines them
sparse_checkout_list = yacpkg.get("include", []).copy()
sparse_checkout_list: list[str] = yacpkg.get("include", []).copy()
if isinstance(package_info, dict):
sparse_checkout_list += package_info.get("include", [])

if yacpkg.get("^sparse_checkout_list") != sparse_checkout_list:
info(progress_print)
exec_shell(f"git sparse-checkout set --no-cone {' '.join(sparse_checkout_list)}")
exec_shell(["git", "sparse-checkout", "set", "--no-cone"] + sparse_checkout_list)
yacpkg["^sparse_checkout_list"] = sparse_checkout_list

# Gets all packages config inside current directory yacpm.json and combine it with the config in the all_packages dict to make sure they are accounted for when fetching the specific dependency package
Expand Down Expand Up @@ -232,7 +235,7 @@ def get_packages(package_names, all_packages: dict, remotes: list):
os.chdir(output_dir)

package_version = package_info.get("version")
if package_version is None:
if not isinstance(package_version, str):
error(f"Expected package {package_name} to have a version field or be a string that is the version")

package_repository = package_info.get("repository")
Expand All @@ -259,8 +262,8 @@ def get_packages(package_names, all_packages: dict, remotes: list):

# Initialize git repository
if not os.path.exists(".git"):
exec_shell("git init")
exec_shell(f"git remote add origin {package_repository}")
exec_shell(["git", "init"])
exec_shell(["git", "remote", "add", "origin",package_repository])
yacpkg["^current_version"] = None

# Freeze package versions to use commit hashes
Expand Down Expand Up @@ -331,7 +334,7 @@ def update_package_info(all_packages: dict, dependency_packages: dict, package_l
if __name__ == "__main__":
# Load yacpm.json
yacpm_file, yacpm = open_read_write("yacpm.json", True)
verbose = yacpm.get("verbose")
VERBOSE = yacpm.get("verbose")

package_list: dict = yacpm["packages"]
remotes = yacpm.get("remotes", ["DEFAULT_REMOTE"])
Expand Down

0 comments on commit 8f10f21

Please sign in to comment.