Skip to content

Commit

Permalink
Fixing recursion bug with smake
Browse files Browse the repository at this point in the history
Also refactored sources to definitions, and adding some error handling
  • Loading branch information
iveevi committed Dec 7, 2021
1 parent 27cec8b commit 0ae6a33
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ One can also simply clone the source and link the `smake` executable.

## How does it work?

Smake searches for all `smake.yaml` files in the current directory, recursively,
and creates the configurations for each target, including all modes and their
Smake searches for a `smake.yaml` file in the current directory and creates configurations for each target, including all modes and their
corresponding builds and post-build scripts, etc.

The structure of an `smake` configuration file is as follows (in no strict
order):

```yaml
# Groups of sources that can be referenced in builds
sources:
# Variables that can be referenced in builds
definitions:
- gsourceA: fileA.c, fileB.c

# List of builds that will be used by the targets
Expand Down Expand Up @@ -87,4 +86,5 @@ Clone this repository and run `smake` to get started (available targets are

- [ ] Pre-build scripts, for cases where source code needs to be auto-generated
- [ ] Add options for parallelizing builds
- [ ] Easier way to define macro arguments for the compilers
- [ ] Easier way to define macro arguments for the compilers
- [ ] Detect changes in included headers
10 changes: 6 additions & 4 deletions example/smake.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
default_compiler: clang++
default_standard: c++14

definitions:
- multisource: multisource/main.cpp, multisource/chip.cpp

builds:
- basic:
- sources: example/basic/main.cpp
- compiler: g++-8
- sources: basic/main.cpp
- multisource:
- sources: example/multisource/main.cpp, example/multisource/chip.cpp
- sources: multisource
- libraries: pthread
- flags: -std=c++11
- multisource_debug:
- sources: example/multisource/main.cpp, example/multisource/chip.cpp
- sources: multisource
- libraries: pthread
- flags: -std=c++11, -g

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name = 'smake',
version = '1.0.0',
version = '1.0.1',
scripts = ['smake'],
author = "Venkataram Edavamadathil Sivaram",
author_email = "vesion4690@gmail.com",
Expand Down
64 changes: 42 additions & 22 deletions smake
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,28 @@ class Target:
postbuild.run(target)

# Global helper functions
def split(d, pr, defns):
prop = d[pr]
if isinstance(prop, str):
def split_plain(elem):
prop = elem
if isinstance(elem, str):
prop = prop.split(', ')

return prop

def split(d, pr, defns):
prop = split_plain(d[pr])

out = []
for i in range(len(prop)):
if prop[i] in defns:
prop[i] = defns[prop[i]]
value = defns[prop[i]]

return prop
if isinstance(value, list):
out.extend(value)
else:
out.append(value)
else:
out.append(prop[i])

return out

def concat(ldicts):
out = {}
Expand All @@ -259,16 +271,9 @@ class Config:
# Initialize targets to empty
self.targets = {}

# Get config files from current dir
configs = []
for root, _, files in os.walk('.'):
for file in files:
if file == 'smake.yaml':
configs.append(os.path.join(root, file))

# Load all files from the current directory
for file in configs:
self.load_file(file)
# Get config file from current dir
if os.path.exists('smake.yaml'):
self.load_file('smake.yaml')

# Reads definitions from variables like sources, includes, etc.
def load_definitions(self, smake):
Expand All @@ -277,10 +282,12 @@ class Config:
# Output dictionary
defns = {}

# Load sources
if 'sources' in smake:
for sgroup in smake['sources']:
defns.update(sgroup)
# Load definitions
if 'definitions' in smake:
for dgroup in smake['definitions']:
key, value = next(iter(dgroup.items()))
value = split_plain(value)
defns.update({key: value})

# Default compiler and standard
if 'default_compiler' in smake:
Expand Down Expand Up @@ -325,7 +332,10 @@ class Config:
libraries, flags)

def load_all_builds(self, smake, defns):
# TODO: check that builds actually exists
# Check that builds actually exists
if 'builds' not in smake:
print(colors.FAIL + 'No builds defined in smake.yaml' + colors.ENDC)
exit(-1)

blist = {}
for b in smake['builds']:
Expand Down Expand Up @@ -373,8 +383,13 @@ class Config:
return Target(name, modes, builds, postbuilds)

def load_all_targets(self, smake, builds, defns):
# Check that targets exist
if 'targets' not in smake:
print(colors.FAIL + 'No targets specified in smake.yaml' + colors.ENDC)
exit(-1)

tlist = {}
for t in smake['targets']: # TODO: error handle presence of targets
for t in smake['targets']:
name = list(t)[0]
target = self.load_target(t, builds, defns)
tlist.update({name: target})
Expand All @@ -398,6 +413,11 @@ class Config:

# List all targets
def list_targets(self):
# Return if no targets
if len(self.targets) == 0:
print(colors.FAIL + 'No targets found' + colors.ENDC)
return

# Max string length of target name
maxlen = 0
for t in self.targets:
Expand Down

0 comments on commit 0ae6a33

Please sign in to comment.