Detect whether the CMake build tree changes locations, such as when CI/CD uses a...
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / general / cmake / CMakeUpToDateWhen.java
blobedcd2b92ae687a061386365a7339020b01200498
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.plugin.general.cmake;
12 import java.io.IOException;
13 import java.nio.file.Files;
14 import java.util.Map;
15 import org.gradle.api.Task;
16 import org.gradle.api.specs.Spec;
18 /**
19 * Check to determine if the CMake build should be successful or not.
21 * @since 2024/03/15
23 public class CMakeUpToDateWhen
24 implements Spec<Task>
26 /**
27 * {@inheritDoc}
28 * @since 2024/03/15
30 @Override
31 public boolean isSatisfiedBy(Task __task)
33 CMakeBuildTask cmakeTask = (CMakeBuildTask)__task;
35 // Configuration is needed?
36 if (CMakeUtils.configureNeeded(cmakeTask))
37 return false;
39 // Cache directory does not exist?
40 if (!Files.isDirectory(cmakeTask.cmakeBuild))
41 return false;
43 // Output is specified but does not exist?
44 if (cmakeTask.cmakeOutFile != null &&
45 !Files.exists(cmakeTask.cmakeOutFile))
46 return false;
48 // Poke the native build system to see if it is out of date
49 try
51 // Load CMake cache
52 Map<String, String> cmakeCache = CMakeUtils.loadCache(
53 cmakeTask.cmakeBuild);
55 // Which generator is being used?
56 String generator = cmakeCache.get("CMAKE_GENERATOR:INTERNAL");
57 switch (generator)
59 case "MSYS Makefiles":
60 case "MinGW Makefiles":
61 case "Unix Makefiles":
62 if (CMakeUtils.cmakeExecutePipe(false,
63 null, null, null,
64 "up-to-date", "--", "-q") != 0)
65 return false;
66 break;
68 case "NMake Makefiles":
69 if (CMakeUtils.cmakeExecutePipe(false,
70 null, null, null,
71 "up-to-date", "--", "/Q") != 0)
72 return false;
73 break;
77 // If this occurs then assume out of date
78 catch (IOException __e)
80 __task.getLogger().warn("Could not determine if out of date.",
81 __e);
82 return false;
85 // Otherwise, success!
86 return true;