1# ===================================== 2# Copyright 2019, Andrew Lindesay 3# Distributed under the terms of the MIT License. 4# ===================================== 5 6# HaikuDepotServer has a number of data-transfer-objects (DTO) that are defined 7# by JSON schemas. The server uses these schemas to produce the objects at 8# compile time. Likewise, the schema files also generate C++ side DTO model 9# objects in the form of .cpp and .h files as well. This way the 10# HaikuDepotServer server and HaikuDepot desktop application are able to 11# communicate more 'safely'. The schema files still need to be copied from 12# the server source to the Haiku source, but the generation process will ensure 13# that the data-structures are consistent. 14# 15# The C++ side classes are generated with python scripts that are included in 16# the Haiku source. These rules and actions take care of making sure that the 17# python scripts are run when necessary to generate the C++ side classes. Note 18# that there are two sorts of classes generated here; the model DTO objects and 19# also the supporting classes that parse the DTO objects. The parsing classes 20# are intended to be used with Haiku JSON parsing systems. 21 22# pragma mark - Generic 23 24actions HdsSchemaGenTouch 25{ 26 touch $(1) 27} 28 29# pragma mark - Model Class Generation 30 31# 1 : the dummy file in the class generation directory (target) 32# 2 : the JSON schema file 33# 3 : the Python script to use 34 35rule HdsSchemaGenModel 36{ 37 SEARCH on $(2) = [ FDirName $(SUBDIR) server schema ] ; 38 SEARCH on $(3) = [ FDirName $(SUBDIR) build scripts ] ; 39 40 MkDir1 $(1:D) ; 41 CleanDir clean : $(1:D) ; 42 Depends $(1) : $(2) $(3) $(1:D) ; 43 HdsSchemaGenModel1 $(1) : $(2) $(3) $(1:D) ; 44} 45 46actions HdsSchemaGenModel1 47{ 48 $(HOST_PYTHON) $(2[2]) -i $(2[1]) --outputdirectory $(2[3]) 49 touch $(1) 50} 51 52# pragma mark - Bulk Parsing Class Generation 53 54# 1 : the dummy file in the class generation directory (target) 55# 2 : the JSON schema file 56# 3 : the Python script to use 57 58rule HdsSchemaGenBulkParser 59{ 60 SEARCH on $(2) = [ FDirName $(SUBDIR) server schema ] ; 61 SEARCH on $(3) = [ FDirName $(SUBDIR) build scripts ] ; 62 63 MkDir1 $(1:D) ; 64 CleanDir clean : $(1:D) ; 65 Depends $(1) : $(2) $(3) $(1:D) ; 66 HdsSchemaGenBulkParser1 $(1) : $(2) $(3) $(1:D) ; 67} 68 69actions HdsSchemaGenBulkParser1 70{ 71 $(HOST_PYTHON) $(2[2]) -i $(2[1]) --outputdirectory $(2[3]) --supportbulkcontainer 72 touch $(1) 73} 74 75# pragma mark - Non-Bulk Parsing Class Generation 76 77# 1 : the dummy file in the class generation directory (target) 78# 2 : the JSON schema file 79# 3 : the Python script to use 80 81rule HdsSchemaGenParser 82{ 83 SEARCH on $(2) = [ FDirName $(SUBDIR) server schema ] ; 84 SEARCH on $(3) = [ FDirName $(SUBDIR) build scripts ] ; 85 86 MkDir1 $(1:D) ; 87 CleanDir clean : $(1:D) ; 88 Depends $(1) : $(2) $(3) $(1:D) ; 89 HdsSchemaGenParser1 $(1) : $(2) $(3) $(1:D) ; 90} 91 92actions HdsSchemaGenParser1 93{ 94 $(HOST_PYTHON) $(2[2]) -i $(2[1]) --outputdirectory $(2[3]) 95 touch $(1) 96} 97 98# pragma mark - Registering Generated Classes 99 100# Because a number of .cpp and .h files will be generated from a single python 101# script's run, it is necessary to introduce a dependency between the known 102# output files and the target for a given python script run. 103 104# 1 : generated files (.h and .cpp) 105# 2 : target directory generated files will be placed in 106# 3 : target that will generate the generated files (dummy file) 107 108rule HdsSchemaGenAppSrcDependsOnGeneration { 109 MakeLocate $(1) : $(2) ; 110 MkDir1 $(2) ; 111 Depends $(1) : $(2) $(3) ; 112 Clean clean : $(1) ; 113 114 # just in case the dummy file ends up being newer than the generated 115 # sources, update the modified timestamp on the generated files. 116 HdsSchemaGenTouch $(1) ; 117} 118