xref: /haiku/src/apps/haikudepot/build/jam/HdsSchemaGenRules (revision 5ac9b506412b11afb993bb52d161efe7666958a5)
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	Clean $(1:D) ;
41	Depends $(1) : $(2) $(3) ;
42
43	MkDir $(1:D) ;
44	HdsSchemaGenModel1 $(1) : $(2) $(3) $(1:D) ;
45	HdsSchemaGenTouch $(1) ;
46}
47
48actions HdsSchemaGenModel1
49{
50	python $(2[2]) -i $(2[1]) --outputdirectory $(2[3])
51}
52
53# pragma mark - Bulk Parsing Class Generation
54
55# 1 : the dummy file in the class generation directory (target)
56# 2 : the JSON schema file
57# 3 : the Python script to use
58
59rule HdsSchemaGenBulkParser
60{
61	SEARCH on $(2) = [ FDirName $(SUBDIR) server schema ] ;
62	SEARCH on $(3) = [ FDirName $(SUBDIR) build scripts ] ;
63
64	Clean $(1:D) ;
65	Depends $(1) : $(2) $(3) ;
66
67	MkDir $(1:D) ;
68	HdsSchemaGenBulkParser1 $(1) : $(2) $(3) $(1:D) ;
69	HdsSchemaGenTouch $(1) ;
70}
71
72actions HdsSchemaGenBulkParser1
73{
74	python $(2[2]) -i $(2[1]) --outputdirectory $(2[3]) --supportbulkcontainer
75}
76
77# pragma mark - Registering Generated Classes
78
79# Because a number of .cpp and .h files will be generated from a single python
80# script's run, it is necessary to introduce a dependency between the known
81# output files and the target for a given python script run.
82
83# 1 : generated files (.h and .cpp)
84# 2 : target that will generate the generated files
85
86rule HdsSchemaGenAppSrcDependsOnGeneration {
87	local generatedSource ;
88	local applicationSource ;
89
90	MakeLocate $(1) : $(2:D) ;
91	Depends $(1) : $(2) ;
92	Clean $(1) ;
93}