Skip to content

Commit 0d6f0f9

Browse files
authored
Merge pull request #35 from flavourworks/master
add support for inline python
2 parents a64b2ae + 5b7f7bd commit 0d6f0f9

File tree

2 files changed

+96
-42
lines changed

2 files changed

+96
-42
lines changed

readme.md

Lines changed: 78 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Examples of working [scripts](https://github.com/polymonster/pmtech/blob/master/
2525
### Built-in Tasks
2626
- copy (copy files from src to dst with single files, folders, globs or regex)
2727
- clean (delete intermediate files)
28+
- shell (run commands directly in the current shell environment)
29+
- python (run inline python defined inside a config file)
2830
- dependencies (track modified times, inouts and output to prevent redundant work)
2931
- delete_orphans (deletes files which no longer have a source parent in dependencies)
3032
- connect (smb network connections with credentials)
@@ -56,17 +58,17 @@ You can run from source code as so, which contains submodules used in some of my
5658

5759
pmbuild requires some submodules so please clone recursively:
5860

59-
```
61+
```text
6062
git clone https://github.com/polymonster/pmbuild.git --recursive
6163
```
6264

6365
When submodules update or new ones are added you can update as follows:
6466

65-
```
67+
```text
6668
git submodule update --init --recursive
6769
```
6870

69-
# Usage
71+
## Usage
7072

7173
Add the pmbuild repository directory / executable installation directory to your path for convenience so you can simply invoke `pmbuild`, otherwise you can locate pmbuild manually and run `<path_to_pmbuild>/pmbuild`.
7274

@@ -99,7 +101,7 @@ Configs are written in [jsn](https://github.com/polymonster/jsn). Define build `
99101

100102
## Running Tasks
101103

102-
```
104+
```text
103105
# runs build tasks
104106
pmbuild <profile> <tasks...>
105107
@@ -112,7 +114,7 @@ pmbuild launch <profile> <args...>
112114

113115
By default you can run all non-explicit tasks by simply running:
114116

115-
```
117+
```text
116118
# run all tasks
117119
pmbuild <profile>
118120
@@ -122,17 +124,17 @@ pmbuild <profile> -all
122124

123125
You can run a single task or a selection of tasks by passing the task name, or you can supply `-n<task_name>` to exclude a task:
124126

125-
```
127+
```text
126128
# runs 2 tasks
127129
pmbuild mac -premake -texturec
128130
129131
# rus all tasks and excludes copy
130132
pmbuild mac -all -ncopy
131133
```
132134

133-
# Help / Display Available Profiles
135+
## Help / Display Available Profiles
134136

135-
```
137+
```text
136138
pmbuild -help
137139
usage:
138140
pmbuild <profile> <tasks...>
@@ -174,9 +176,9 @@ profiles:
174176
android
175177
```
176178

177-
# Display Available Tasks For Profile
179+
## Display Available Tasks For Profile
178180

179-
```
181+
```text
180182
pmbuild <profile> -help
181183
available tasks for profile mac:
182184
config.jsn (edit task settings or add new ones in here)
@@ -191,13 +193,13 @@ available tasks for profile mac:
191193
pmbuild_config
192194
```
193195

194-
# Display Help For Task
196+
## Display Help For Task
195197

196-
```
198+
```text
197199
pmbuild <profile> -<task> -help
198200
```
199201

200-
# Variables and Inheritence
202+
## Variables and Inheritence
201203

202204
jsn allows inheritance and variables `${variable}` evaluated with dollar sign where variables are defined in the script. This allows sharing and re-use of tasks to make configs more compact.
203205

@@ -217,11 +219,11 @@ jsn allows inheritance and variables `${variable}` evaluated with dollar sign wh
217219
}
218220
```
219221

220-
# Special / User Variables
222+
## Special / User Variables
221223

222224
pmbuild also provides special variables evaluated with percentage sign as so `%{variable_name}` these are evaluated at runtime, configurable per user and stored in `config.user.jsn` in addition to supplying your own user args there are some built in ones as well:
223225

224-
```
226+
```text
225227
%{profile} = current building profile (ie mac, win32, linux etc)
226228
%{cwd} = current working directory
227229
%{username} = user name of the machine
@@ -235,11 +237,26 @@ pmbuild also provides special variables evaluated with percentage sign as so `%{
235237

236238
You can also pass `-vars` to pmbuild from the commandline as a string of jsn:
237239

238-
```
240+
```text
239241
pmbuild profile -vars "var_bool: true, var_int: 1, var_string:'test', var_obj:{key: value}"
240242
```
241243

242-
# Copy / Files
244+
You can initialise user vars to default values and have the `-vars` passed to the commandline override them as so:
245+
246+
```yaml
247+
task: {
248+
user_vars: {
249+
var_or_default: "default_value"
250+
}
251+
shell: {
252+
commands: [
253+
"echo %{var_or_default}"
254+
]
255+
}
256+
}
257+
```
258+
259+
## Copy / Files
243260

244261
You can copy files with a copy task, this is often necessary to move files into a data directory or deploy to a dev kit, simply specify an array of file pairs (source, destination) in a task of type copy. Here you can supply [glob](https://docs.python.org/3/library/glob.html) or [regex](https://docs.python.org/3/library/re.html) to find files, a directory or a single file:
245262

@@ -290,6 +307,7 @@ copy-change-ext:
290307
change_ext: ".newext"
291308
}
292309
```
310+
293311
You can also specify `excludes` which is an [fnmatch](https://docs.python.org/3/library/fnmatch.html) to further filter files after they are expanded by directory, regex or glob:
294312

295313
```yaml
@@ -313,7 +331,7 @@ texturec: {
313331

314332
It is possible to further filter the files processed by using the commandline argument `-filter_files "*.*"` this is an [fnmatch](https://docs.python.org/3/library/fnmatch.html) which you can supply each time you make a commandline invocation. This feature is usefult to isolate certain file extensions `*.lua` or a single file `path/single_file.txt` should you need to run and debug a a tool or process.
315333

316-
# Clean
334+
## Clean
317335

318336
Clean out stale data and build from fresh, you can define clean tasks which will delete these directories:
319337

@@ -328,11 +346,10 @@ clean: {
328346
}
329347
```
330348

331-
# Tools
349+
## Tools
332350

333351
Run your own tools or scripts and feed them files with the `files` objects as described in the copy task. We can register different tools for <mac, windows or linux>.
334352

335-
336353
```yaml
337354
{
338355
tools<mac>: {
@@ -408,7 +425,25 @@ tools_update: {
408425

409426
Run `pmbuild update` to update any tools to `latest` versions or specific tagged version using the `tag_name` parameter.
410427

411-
# Extension Python Modules
428+
## Shell / Inline Python
429+
430+
You can supply shell commands or inline python inside scripts as so:
431+
432+
```yaml
433+
shell: {
434+
commands: [
435+
"echo hello world"
436+
]
437+
}
438+
439+
python: {
440+
code: [
441+
"print('hello world!')"
442+
]
443+
}
444+
```
445+
446+
## Extension Python Modules
412447

413448
You can register and call extension modules written in python, specify a path to the python module directory, the module name (.py file) and a function name to invoke when the build runs:
414449

@@ -428,7 +463,7 @@ extensions: {
428463
}
429464
```
430465

431-
# Export Config Files
466+
## Export Config Files
432467

433468
You can use `export.jsn` files in data directories to specify per directory or per file command line arguments to run. For example when converting textures we may want certain textures to be converted to a different format to others. export.jsn files override each other hierarchically by directory so you can have a single export.jsn at the root of a directory tree.
434469

@@ -472,7 +507,7 @@ You can specify `rules` which select files and apply different settings. jsn inh
472507
}
473508
```
474509

475-
# Dependencies
510+
## Dependencies
476511

477512
With builds you can choose to output dependency info containing build and file timestamps, the commandline used to build and a list of input and output files used during a build. Add `dependencies: true` to any tool with a `files` object to generate an output `.dep` file for each file that is built, subsequent builds will skip if the dependencies remain up-to-date. Dependency info is output in json and can be used in other tools as well to trigger hot reloading.
478513

@@ -491,6 +526,7 @@ render_configs: {
491526
dependencies: true
492527
}
493528
```
529+
494530
```json
495531
{
496532
"cmdline": "../third_party/pmbuild/bin/mac/texturec -f assets/textures/blend_test_fg.png -t RGBA8 --mips -o bin/osx/data/textures/blend_test_fg.dds ",
@@ -506,8 +542,7 @@ render_configs: {
506542
}
507543
```
508544

509-
510-
# Containers
545+
## Containers
511546

512547
Sometimes in source asset data we may have a collection of files in a directory we want to group together to concatonate or merge them... for instance if we have individual images for cubemap faces and we want to pass them to a tool to spit out a single cubemap texture. Specify container and `files` comprised of an array of filenames or globs, these files will be written into a `.container.txt` file you can forward to other tools.
513548

@@ -536,15 +571,15 @@ Sometimes in source asset data we may have a collection of files in a directory
536571
}
537572
```
538573

539-
# Task Types
574+
## Task Types
540575

541576
Each task has a type, you can define this using the `type` member, if the name of the task is the same as a tool, extension or built in function then the `type` member is implicitly added.
542577

543578
```yaml
544579
copy:
545580
{
546581
files: [
547-
// ..
582+
// ..
548583
]
549584
}
550585

@@ -558,11 +593,11 @@ copy-second:
558593
}
559594
```
560595

561-
# Make
596+
## Make
562597

563598
Make is a special command which is specified before the profile
564599

565-
```
600+
```text
566601
pmbuild make <profile> <target>
567602
```
568603

@@ -577,11 +612,11 @@ make: {
577612
}
578613
```
579614

580-
# Launch
615+
## Launch
581616

582617
Launch is a special command like make which can be invoked as follows:
583618

584-
```
619+
```text
585620
pmbuild launch <profile> <target>
586621
```
587622

@@ -596,27 +631,27 @@ launch: {
596631
}
597632
```
598633

599-
# Tool
634+
## Tool
600635

601636
You can bypass the need for build profiles and run any of the tools you have registered in your pmbuild `config.jsn`. use the following command and the pass `-args` anything after args is passed directly to the tool.
602637

603-
```
638+
```text
604639
pmbuild tool ffmpeg -args -i input.mov -c:v libx264 -crf 26 output.mp4
605640
```
606641

607642
You can also supply `files` from the commandline to process globs, handled in the same way as the files pbject from within a `config.jsn`
608643

609-
```
644+
```text
610645
pmbuild tool ffmpeg -files "[['source/**.mov'], ['output']]" -args -i %{input_file} -c:v libx264 -crf 26 %{output_file}
611646
```
612647

613-
# Network Connections / Credentials
648+
## Network Connections / Credentials
614649

615650
In a development environment we may need to synchronise large amounts of data which is stored on a server, or we may need to build artifacts to a server or deploy to a dev kit. we can mount connections to local area network connections via smb. You can supply credentials for the network connects in plain text, or encrypt them with cryptographic quality encryption to be stored and accessed with a password.
616651

617652
To use encrypted credentials you need to install the python cryptography module:
618653

619-
```
654+
```text
620655
pip install cryptography
621656
```
622657

@@ -645,7 +680,7 @@ connect-server:
645680

646681
To add to the credentials file run:
647682

648-
```
683+
```text
649684
pmbuild -credentials
650685
```
651686

@@ -657,7 +692,7 @@ A file `credentials.unlocked.jsn` will be generated in the current working direc
657692
}
658693
```
659694

660-
# Explicit Tasks
695+
## Explicit Tasks
661696

662697
Tasks can be marked as explicit so that you must specify `-<task_name>` from the commandline and they do not get included automatically with `-all`. This is useful if you have build tasks which you may only need to run infrequently and take a long time to complete. Building third party libraries which are updated infrequently is an example where this can be useful:
663698

@@ -674,7 +709,7 @@ libs: {
674709
}
675710
```
676711

677-
# Hidden Profiles and Tasks
712+
## Hidden Profiles and Tasks
678713

679714
Tasks and profiles which are marked hidden will not be included in the list returned by `pmbuild -help`. The behaviour of the task or profile is not otherwise affected in any way. This is useful for streamlining the list of commands displayed to the user, or for excluding tasks/profiles which are never called explicitly (e.g. ones that are solely used as a base for inheritance). In the example below, setting the base task `copy_videos_base` to hidden and explicit makes it impossible for a user to call this generic version.
680715

@@ -700,7 +735,7 @@ copy_mp4_files(copy_base):
700735

701736
```
702737

703-
# Enable/Disable Tasks
738+
## Enable/Disable Tasks
704739

705740
Individual tasks in a given profile can be enabled/disabled by setting `enable: true` or `enable: false`. Tasks default to being enabled, and the enabled value is inherited across profiles. This makes it possible to inherit from a profile and make only certain tasks enabled or disabled. In the example below, `child_profile` would run `task_1` and `task_2`, whereas `base_profile` only runs `task_2`.
706741

@@ -733,7 +768,7 @@ child_profile(base_profile):
733768

734769
```
735770

736-
# Build Order
771+
## Build Order
737772

738773
By default tasks are built in the order they are specified in the config.jsn files. When using jsn inheritance it may not be clear what the build order might be or you may want to specify an explicit build order. You can do this using the `build_order` lists.
739774

@@ -755,7 +790,7 @@ post_build_order" [
755790

756791
Each of the build order lists is optional. If you do not specify a task name in any of the build order lists it will be appended to the `build_order` list.
757792

758-
# vscode
793+
## vscode
759794

760795
pmbuild can generate `launch.json`, `tasks.json` and `.code-workspace` files for vscode which use pmbuild and a configured make toolchain to build code and launch the exectuable for debugging.
761796

@@ -789,4 +824,5 @@ vscode: {
789824
cwd: "bin/osx"
790825
}
791826
```
827+
792828
You should install the vscode C/C++ extension, install and configure whatever debugger you would like tou use. You can supply different debuggers to the `debugger` member, such as `lldb` (cppdbg) or `gdb` (cppdbg) or `vscode` (cppvsdbg) depending on what you have installed.

0 commit comments

Comments
 (0)