mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Read version from Cargo.toml (#1267)
This commit is contained in:
parent
07369a6270
commit
40d6daf824
6 changed files with 57 additions and 5 deletions
19
BUILD.gn
19
BUILD.gn
|
@ -119,12 +119,25 @@ group("deno_deps") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Reads the cargo info from Cargo.toml
|
||||||
|
deno_cargo_info = exec_script("build_extra/rust/get_cargo_info.py",
|
||||||
|
[ rebase_path("Cargo.toml", root_build_dir) ],
|
||||||
|
"json")
|
||||||
|
|
||||||
rust_executable("deno") {
|
rust_executable("deno") {
|
||||||
source_root = "src/main.rs"
|
source_root = "src/main.rs"
|
||||||
extern = main_extern
|
extern = main_extern
|
||||||
deps = [
|
deps = [
|
||||||
":deno_deps",
|
":deno_deps",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Extract version from Cargo.toml
|
||||||
|
# TODO integrate this into rust.gni by allowing the rust_executable template
|
||||||
|
# to specify a cargo.toml from which it will extract a version.
|
||||||
|
crate_version = deno_cargo_info.version
|
||||||
|
inputs = [
|
||||||
|
"Cargo.toml",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
rust_test("test_rs") {
|
rust_test("test_rs") {
|
||||||
|
@ -133,6 +146,12 @@ rust_test("test_rs") {
|
||||||
deps = [
|
deps = [
|
||||||
":deno_deps",
|
":deno_deps",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Extract version from Cargo.toml
|
||||||
|
crate_version = deno_cargo_info.version
|
||||||
|
inputs = [
|
||||||
|
"Cargo.toml",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
rust_executable("hyper_hello") {
|
rust_executable("hyper_hello") {
|
||||||
|
|
1
build_extra/rust/get_cargo_info.cmd
Normal file
1
build_extra/rust/get_cargo_info.cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
@"%PYTHON_EXE%" "%~dpn0.py" %*
|
14
build_extra/rust/get_cargo_info.py
Executable file
14
build_extra/rust/get_cargo_info.py
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
|
# Read the package version from Cargo.toml and output as json
|
||||||
|
cargo_toml_path = sys.argv[1]
|
||||||
|
|
||||||
|
for line in open(cargo_toml_path):
|
||||||
|
match = re.search('version = "(.*)"', line)
|
||||||
|
if match:
|
||||||
|
print('{"version": "' + match.group(1) + '"}')
|
||||||
|
break
|
|
@ -1,13 +1,24 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# This file just executes its arguments, except that also adds GN_OUT_DIR to the
|
# This file just executes its arguments, except that also adds GN_OUT_DIR and
|
||||||
# environ. This is for compatibility with cargo.
|
# CARGO_PKG_VERSION to the environ. This is for compatibility with cargo.
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
# This is for src/msg.rs to know where to find msg_generated.rs.
|
# This is for src/msg.rs to know where to find msg_generated.rs.
|
||||||
# When building with Cargo this variable is set by build.rs.
|
# When building with Cargo this variable is set by build.rs.
|
||||||
os.environ["GN_OUT_DIR"] = os.path.abspath(".")
|
os.environ["GN_OUT_DIR"] = os.path.abspath(".")
|
||||||
assert os.path.isdir(os.environ["GN_OUT_DIR"])
|
assert os.path.isdir(os.environ["GN_OUT_DIR"])
|
||||||
|
|
||||||
sys.exit(subprocess.call(sys.argv[1:]))
|
# Set the CARGO_PKG_VERSION env variable if provided as an argument
|
||||||
|
# When building with Cargo this variable is set automatically
|
||||||
|
args = sys.argv[1:]
|
||||||
|
for i, arg in enumerate(args):
|
||||||
|
match = re.search('--cargo-pkg-version="?([^"]*)"?', arg)
|
||||||
|
if match:
|
||||||
|
os.environ["CARGO_PKG_VERSION"] = match.group(1)
|
||||||
|
del args[i]
|
||||||
|
break
|
||||||
|
|
||||||
|
sys.exit(subprocess.call(args))
|
||||||
|
|
|
@ -49,6 +49,7 @@ template("rust_crate") {
|
||||||
"crate_type",
|
"crate_type",
|
||||||
"crate_version",
|
"crate_version",
|
||||||
"deps",
|
"deps",
|
||||||
|
"inputs",
|
||||||
"features",
|
"features",
|
||||||
"is_test",
|
"is_test",
|
||||||
"libs",
|
"libs",
|
||||||
|
@ -190,6 +191,13 @@ template("rust_crate") {
|
||||||
"--color=always",
|
"--color=always",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (defined(crate_version)) {
|
||||||
|
args += [
|
||||||
|
# This is used to set env variables for Cargo build compatibility
|
||||||
|
"--cargo-pkg-version=$crate_version",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
if (is_debug) {
|
if (is_debug) {
|
||||||
args += [ "-g" ]
|
args += [ "-g" ]
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
use libdeno;
|
use libdeno;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
|
|
||||||
// TODO Extract this version string from Cargo.toml.
|
pub const DENO: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub const DENO: &str = "0.2.2";
|
|
||||||
|
|
||||||
pub fn v8() -> &'static str {
|
pub fn v8() -> &'static str {
|
||||||
let version = unsafe { libdeno::deno_v8_version() };
|
let version = unsafe { libdeno::deno_v8_version() };
|
||||||
|
|
Loading…
Add table
Reference in a new issue