Machine.h 5.2 KB

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