Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 37 additions & 100 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,37 @@
# Ninja

Ninja is a small build system with a focus on speed.
https://ninja-build.org/

See [the manual](https://ninja-build.org/manual.html) or
`doc/manual.asciidoc` included in the distribution for background
and more details.

Binaries for Linux, Mac and Windows are available on
[GitHub](https://github.com/ninja-build/ninja/releases).
Run `./ninja -h` for Ninja help.

Installation is not necessary because the only required file is the
resulting ninja binary. However, to enable features like Bash
completion and Emacs and Vim editing modes, some files in misc/ must be
copied to appropriate locations.

If you're interested in making changes to Ninja, read
[CONTRIBUTING.md](CONTRIBUTING.md) first.

## Building Ninja itself

You can either build Ninja via the custom generator script written in Python or
via CMake. For more details see
[the wiki](https://github.com/ninja-build/ninja/wiki).

### Python

```
./configure.py --bootstrap
```

This will generate the `ninja` binary and a `build.ninja` file you can now use
to build Ninja with itself.

If you have a GoogleTest source directory, you can build the tests
by passing its path with `--gtest-source-dir=PATH` option, or the
`GTEST_SOURCE_DIR` environment variable, e.g.:

```
./configure.py --bootstrap --gtest-source-dir=/path/to/googletest
./ninja all # build ninja_test and other auxiliary binaries
./ninja_test` # run the unit-test suite.
```

Use the CMake build below if you want to use a preinstalled binary
version of the library.

### CMake

```
cmake -Bbuild-cmake
cmake --build build-cmake
```

The `ninja` binary will now be inside the `build-cmake` directory (you can
choose any other name you like).

To run the unit tests:

```
./build-cmake/ninja_test
```

## Generating documentation

### Ninja Manual

You must have `asciidoc` and `xsltproc` in your PATH, then do:

```
./configure.py
ninja manual doc/manual.pdf
```

Which will generate `doc/manual.html`.

To generate the PDF version of the manual, you must have `dblatext` in your PATH then do:

```
./configure.py # only if you didn't do it previously.
ninja doc/manual.pdf
```

Which will generate `doc/manual.pdf`.

### Doxygen documentation

If you have `doxygen` installed, you can build documentation extracted from C++
declarations and comments to help you navigate the code. Note that Ninja is a standalone
executable, not a library, so there is no public API, all details exposed here are
internal.

```
./configure.py # if needed
ninja doxygen
```

Then open `doc/doxygen/html/index.html` in a browser to look at it.
# Shadowdash Converter

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this replacing the stock ninja readme!?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if that is a part of the ninja like here, I believe rewriting the stock ninja readme is kinda wrong in this case

## Build
```sh
./build.sh
```
This will create the converter in the `debug-build` directory with debug symbols with the name 'shadowdash'.

## Run
```sh
./debug-build/shadowdash -f <path-to-build.ninja>
```
If `-f` argument is not given, it will use the `build.ninja` file in the current working directory.
Output file is named `output.cc`. Output is also printed on stdout.

## Test Suite
```sh
cd converter
./run-tests.sh
```
This will run the converter with input `build.ninja` files from the `converter/testing/` directory.

## Directory Structure
```sh
- README.md # readme for the converter
- build.sh # builds the converter binary in debug-build/ folder with the name shadowdash
- src/ # contains the converter source code, previously contained ninja source code
- converter/
- include/
- manifest.h # contains definitions for shadowdash namespace that are required to compile the output of the converter into a library
- testing/
- example.build.ninja
- example.zlib.ninja
- run-tests.sh
```

## Converter Implementation
- The converter converts any given `build.ninja` to Team 5's single file language spec.
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake -DCMAKE_BUILD_TYPE=Debug -B debug-build
cmake --build debug-build --parallel --config Debug --target ninja
mv debug-build/ninja debug-build/shadowdash
234 changes: 234 additions & 0 deletions converter/include/manifest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <utility>

namespace shadowdash {

class Token {
public:
enum Type { LITERAL, VAR };

Token(Type type, std::string value)
: type_(type), value_(std::move(value)) {
//std::cout << "creating " << type << " : " << value_ << std::endl;
}

Token(std::string value) : Token(Token::LITERAL, std::move(value)) {
//std::cout << "creating LITERAL: " << value_ << std::endl;
}

Token(const char* value) : Token(Token::LITERAL, std::string(value)) {
//std::cout << "creating LITERAL: " << value << std::endl;
}

Type type_;
std::string value_;
};

// Overload operator<< for Token
std::ostream& operator<<(std::ostream& os, const Token& token) {
os << (token.type_ == Token::LITERAL ? "LITERAL" : "VAR") << ": " << token.value_;
return os;
}

Token operator"" _l(const char* value, std::size_t len) {
return Token(Token::Type::LITERAL, std::string(value, len));
}

Token operator"" _v(const char* value, std::size_t len) {
return Token(Token::Type::VAR, std::string(value, len));
}

class str {
public:
str(std::vector<Token> tokens) : tokens_(std::move(tokens)) {
//std::cout << "creating str: ";
for (const auto& token : tokens_) {
//std::cout << token << " ";
}
//std::cout << std::endl;
}

std::vector<Token> tokens_;
};

// Overload operator<< for str
std::ostream& operator<<(std::ostream& os, const str& s) {
os << "str: [";
for (const auto& token : s.tokens_) {
os << token << ", ";
}
os << "]";
return os;
}

using binding = std::pair<std::string, str>;
using map = std::vector<binding>;

class list {
public:
list(std::vector<str> values) : values_(std::move(values)) {
//std::cout << "creating list: ";
for (const auto& value : values_) {
//std::cout << value << " ";
}
//std::cout << std::endl;
}

std::vector<str> values_;
};

// Overload operator<< for list
std::ostream& operator<<(std::ostream& os, const list& l) {
os << "list: [";
for (const auto& value : l.values_) {
os << value << ", ";
}
os << "]";
return os;
}

class var {
public:
var(const char* name, str value) : name_(name), value_(std::move(value)) {}

const char* name_;
str value_;
};

// Overload operator<< for var
std::ostream& operator<<(std::ostream& os, const var& v) {
os << "var: " << v.name_ << ", " << v.value_;
return os;
}


class rule {
public:
enum SPECIAL_RULE {
phony
};

union _rule {
_rule() : sp_rule(phony) {}
_rule(map bindings) : bindings_(std::move(bindings)) {}
_rule(SPECIAL_RULE sr) : sp_rule(sr) {}
~_rule() {}

map bindings_;
SPECIAL_RULE sp_rule;
} _rule_data;
bool is_special;

rule(map bindings) : _rule_data(std::move(bindings)), is_special(false) {}
rule(SPECIAL_RULE sp_rule) : _rule_data(sp_rule), is_special(true) {}

rule(const rule& other) : is_special(other.is_special) {
if (is_special) {
new (&_rule_data) _rule(other._rule_data.sp_rule); // Copy the special rule
} else {
new (&_rule_data) _rule(other._rule_data.bindings_); // Copy the bindings map
}
}
};

// Overload operator<< for rule
std::ostream& operator<<(std::ostream& os, const rule& r) {
os << "rule: [";
if(r.is_special)
os << r._rule_data.sp_rule;
else {
for (const auto& binding : r._rule_data.bindings_) {
os << binding.first << ": " << binding.second << ", ";
}
}
os << "]";
return os;
}

class build {
public:
build(
list outputs,
list implicit_outputs,
rule rule,
list inputs,
list implicit_inputs,
list order_only_inputs,
map bindings)
: outputs_(std::move(outputs)),
implicit_outputs_(std::move(implicit_outputs)),
rule_(rule),
inputs_(std::move(inputs)),
implicit_inputs_(std::move(implicit_inputs)),
order_only_inputs_(std::move(order_only_inputs)),
bindings_(std::move(bindings)) {
//std::cout << "creating build: ";
//std::cout << "creating build outputs: ";
//std::cout << this->outputs_ << std::endl;
}

list outputs_;
list implicit_outputs_;
rule rule_;
list inputs_;
list implicit_inputs_;
list order_only_inputs_;
map bindings_;
};

// Overload operator<< for build
std::ostream& operator<<(std::ostream& os, const build& b) {
os << "build: { "
<< "outputs: " << b.outputs_ << ", "
<< "implicit_outputs: " << b.implicit_outputs_ << ", "
<< "rule: " << b.rule_ << ", "
<< "inputs: " << b.inputs_ << ", "
<< "implicit_inputs: " << b.implicit_inputs_ << ", "
<< "order_only_inputs: " << b.order_only_inputs_ << ", "
<< "bindings: [";
for (const auto& binding : b.bindings_) {
os << binding.first << ": " << binding.second << ", ";
}
os << "] }";
return os;
}

class buildGroup {
public:
buildGroup(std::vector<build> builds) : builds(std::move(builds)) {}

std::vector<build> builds;
};

// Overload operator<< for buildGroup
std::ostream& operator<<(std::ostream& os, const buildGroup& bg) {
os << "buildGroup: [";
for (const auto& b : bg.builds) {
os << b << ", ";
}
os << "]";
return os;
}

static auto in = "in"_v;
static auto out = "out"_v;

} // namespace shadowdash

#define let(name, ...) \
var name { \
#name, str { \
__VA_ARGS__ \
} \
}

#define bind(name, ...) \
{ \
#name, str { \
__VA_ARGS__ \
} \
}
Loading