Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Commit

Permalink
Remakes paradise changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AffectedArc07 committed Jul 17, 2020
1 parent 0cee19e commit 1686ef0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
rust-g (pronounced rusty-g) is a library which offloads certain expensive or
difficult tasks from BYOND.

This library is currently used in the [tgstation] codebase, and is required for
This library is currently used in the Paradise codebase, and is required for
it to run. A pre-compiled DLL version can be found in the repo root, but you
can build your own from this repo at your preference. Builds can also be found
on the [releases page].

[releases page]: https://github.com/tgstation/rust-g/releases
[releases page]: https://github.com/ParadiseSS13/rust-g/releases

## Dependencies

Expand All @@ -33,7 +33,7 @@ The [Rust] compiler:

```sh
# Clone the `rust-g` repository to a directory of your choice
git clone https://github.com/tgstation/rust-g.git
git clone https://github.com/ParadiseSS13/rust-g.git
# in the `rust-g` directory...
cd rust-g
# Linux
Expand All @@ -58,7 +58,7 @@ System libraries:

The [cargo] tool handles compilation, as well as automatically downloading and
compiling all Rust dependencies. The default configuration is suitable for
use with the [tgstation] codebase. To compile in release mode (recommended for
use with the Paradise codebase. To compile in release mode (recommended for
speed):

```sh
Expand All @@ -78,7 +78,6 @@ cargo build --release --features dmi,file,log,url,http
The default features are:
* log: Faster log output.
* dmi: DMI manipulations which are impossible from within BYOND.
Used by the asset cache subsystem to improve load times.
* git: Functions for robustly checking the current git revision.
* http: Asynchronous HTTP(s) client supporting most standard methods.
* sql: Asynchronous MySQL/MariaDB client library.
Expand Down Expand Up @@ -133,14 +132,14 @@ it is included in the `LD_LIBRARY_PATH` environment variable, or tweak the searc
logic in `rust_g.dm`:

```sh
$ export LD_LIBRARY_PATH=/path/to/tgstation
$ export LD_LIBRARY_PATH=/path/to/paradise
```

To examine what locations BYOND is searching for the shared library, use
`strace`:

```sh
$ strace DreamDaemon tgstation.dmb 45000 -trusted -logself 2>&1 | grep 'rust_g'
$ strace DreamDaemon paradise.dmb 6666 -trusted -logself 2>&1 | grep 'rust_g'
# Early in output, the file will be listed when BYOND examines every file it can see:
open("rust_g", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = -1 ENOTDIR (Not a directory)
# BYOND will then search some common directories...
Expand All @@ -161,10 +160,6 @@ open("rust_g", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = -1 ENOTD
If you're still having problems, ask in the [Coderbus Discord]'s
`#tooling-questions` channel.

You can also try [tgstation]'s IRC, `#coderbus` on Rizon, but it is usually
quiet.
[tgstation]: https://github.com/tgstation/tgstation
[Rust]: https://rust-lang.org
[cargo]: https://doc.rust-lang.org/cargo/
[rustup]: https://rustup.rs/
Expand Down
51 changes: 23 additions & 28 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,12 @@ thread_local! {
static FILE_MAP: RefCell<HashMap<OsString, File>> = RefCell::new(HashMap::new());
}

byond_fn! { log_write(path, data, ...rest) {
FILE_MAP.with(|cell| -> Result<()> {
// open file
let mut map = cell.borrow_mut();
let path = Path::new(&path as &str);
let file = match map.entry(path.into()) {
Entry::Occupied(elem) => elem.into_mut(),
Entry::Vacant(elem) => elem.insert(open(path)?),
};

if rest.first().map(|x| &**x) == Some("false") {
// Write the data to the file with no accoutrements.
write!(file, "{}", data)?;
} else {
// write first line, timestamped
let mut iter = data.split('\n');
if let Some(line) = iter.next() {
write!(file, "[{}] {}\n", Utc::now().format("%F %T%.3f"), line)?;
}

// write remaining lines
for line in iter {
write!(file, " - {}\n", line)?;
}
}

Ok(())
}).err()
byond_fn! { log_write(path, data) {
data.split('\n')
.map(|line| format(line))
.map(|line| write(path, line))
.collect::<Result<Vec<_>>>()
.err()
} }

byond_fn! { log_close_all() {
Expand All @@ -52,6 +30,23 @@ byond_fn! { log_close_all() {
Some("")
} }

fn format(data: &str) -> String {
format!("[{}] {}\n", Utc::now().format("%FT%T"), data)
}

fn write(path: &str, data: String) -> Result<usize> {
FILE_MAP.with(|cell| {
let mut map = cell.borrow_mut();
let path = Path::new(path);
let file = match map.entry(path.into()) {
Entry::Occupied(elem) => elem.into_mut(),
Entry::Vacant(elem) => elem.insert(open(path)?),
};

Ok(file.write(&data.into_bytes())?)
})
}

fn open(path: &Path) -> Result<File> {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?
Expand Down

0 comments on commit 1686ef0

Please sign in to comment.