Machine.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. 
  2. #ifndef DSR_BUILDER_MACHINE_MODULE
  3. #define DSR_BUILDER_MACHINE_MODULE
  4. #include "../../DFPSR/api/stringAPI.h"
  5. using namespace dsr;
  6. struct Flag {
  7. // Flags created externally using argumentsToSettings from either the command line or another project, will be marked as inherited and given to the next call.
  8. bool inherited;
  9. dsr::String key, value;
  10. Flag() {}
  11. Flag(const dsr::ReadableString &key, const dsr::ReadableString &value, bool inherited)
  12. : key(key), value(value), inherited(inherited) {}
  13. };
  14. struct Machine {
  15. List<Flag> variables;
  16. List<String> compilerFlags;
  17. List<String> linkerFlags;
  18. // When activeStackDepth < currentStackDepth, we are skipping false cases.
  19. int64_t currentStackDepth = 0; // How many scopes we are inside of, from the root script including all the others.
  20. int64_t activeStackDepth = 0;
  21. };
  22. enum class Extension {
  23. Unknown, H, Hpp, C, Cpp
  24. };
  25. enum class ScriptLanguage {
  26. Unknown,
  27. Batch,
  28. Bash
  29. };
  30. Extension extensionFromString(const ReadableString& extensionName);
  31. struct Connection {
  32. String path;
  33. int64_t lineNumber = -1;
  34. int64_t dependencyIndex = -1;
  35. Connection(const ReadableString& path)
  36. : path(path) {}
  37. Connection(const ReadableString& path, int64_t lineNumber)
  38. : path(path), lineNumber(lineNumber) {}
  39. };
  40. struct Dependency {
  41. String path;
  42. Extension extension;
  43. uint64_t contentChecksum;
  44. bool visited; // Used to avoid infinite loops while traversing dependencies.
  45. List<Connection> links; // Depends on having these linked after compiling.
  46. List<Connection> includes; // Depends on having these included in pre-processing.
  47. Dependency(const ReadableString& path, Extension extension, uint64_t contentChecksum)
  48. : path(path), extension(extension), contentChecksum(contentChecksum) {}
  49. };
  50. struct ProjectContext {
  51. //Machine settings;
  52. List<Dependency> dependencies;
  53. ProjectContext() {}
  54. };
  55. struct SourceObject {
  56. uint64_t identityChecksum = 0; // Identification number for the object's name.
  57. uint64_t combinedChecksum = 0; // Combined content of the source file and all included headers recursively.
  58. String sourcePath, objectPath, generatedCompilerFlags, compilerName, compileFrom;
  59. SourceObject(uint64_t identityChecksum, uint64_t combinedChecksum, const ReadableString& sourcePath, const ReadableString& objectPath, const ReadableString& generatedCompilerFlags, const ReadableString& compilerName, const ReadableString& compileFrom)
  60. : identityChecksum(identityChecksum), combinedChecksum(combinedChecksum), sourcePath(sourcePath), objectPath(objectPath), generatedCompilerFlags(generatedCompilerFlags), compilerName(compilerName), compileFrom(compileFrom) {}
  61. };
  62. struct LinkingStep {
  63. String compilerName, compileFrom, binaryName;
  64. List<String> linkerFlags;
  65. List<int64_t> sourceObjectIndices;
  66. bool executeResult;
  67. LinkingStep(const ReadableString &compilerName, const ReadableString &compileFrom, const ReadableString &binaryName, const List<String> &linkerFlags, const List<int64_t> &sourceObjectIndices, bool executeResult)
  68. : compilerName(compilerName), compileFrom(compileFrom), binaryName(binaryName), linkerFlags(linkerFlags), sourceObjectIndices(sourceObjectIndices), executeResult(executeResult) {}
  69. };
  70. struct SessionContext {
  71. String tempPath;
  72. String executableExtension;
  73. List<SourceObject> sourceObjects;
  74. List<LinkingStep> linkerSteps;
  75. SessionContext(const ReadableString &tempPath, const ReadableString &executableExtension)
  76. : tempPath(tempPath), executableExtension(executableExtension) {}
  77. };
  78. // Returns the first case insensitive match for key in target, or -1 if not found.
  79. int64_t findFlag(const Machine &target, const dsr::ReadableString &key);
  80. // Returns the value of key in target, or defaultValue if not found.
  81. ReadableString getFlag(const Machine &target, const dsr::ReadableString &key, const dsr::ReadableString &defaultValue);
  82. // Returns the value of key in target, defaultValue if not found, or 0 if not an integer.
  83. int64_t getFlagAsInteger(const Machine &target, const dsr::ReadableString &key, int64_t defaultValue = 0);
  84. // Assigns value to key in target. Allocates key in target if it does not already exist.
  85. void assignValue(Machine &target, const dsr::ReadableString &key, const dsr::ReadableString &value, bool inherited);
  86. // Modifies the flags in target, while listing source files to context, using the script in scriptPath.
  87. // Recursively including other scripts using the script's folder as the origin for relative paths.
  88. void evaluateScript(SessionContext &output, ProjectContext &context, Machine &target, const ReadableString &scriptPath);
  89. // Build anything in projectPath.
  90. void build(SessionContext &output, const ReadableString &projectPath, Machine &settings);
  91. // Build the project in projectFilePath.
  92. // Settings must be taken by value to prevent side-effects from spilling over between different scripts.
  93. void buildProject(SessionContext &output, const ReadableString &projectFilePath, Machine settings);
  94. // Build all projects in projectFolderPath.
  95. void buildProjects(SessionContext &output, const ReadableString &projectFolderPath, Machine &settings);
  96. void argumentsToSettings(Machine &settings, const List<String> &arguments, int64_t firstArgument);
  97. #endif