Skip to content
Permalink
Browse files

Merge pull request #870 from fniephaus/non-git-repo

Ensure topaz builds when not in a git repository
  • Loading branch information
timfel committed Mar 22, 2017
2 parents 1c7f1f9 + 6ff79ac commit 82ff449a7a49d46c4d9e2da5bedc1abb40085435
Showing with 46 additions and 32 deletions.
  1. +3 −32 topaz/main.py
  2. +19 −0 topaz/objspace.py
  3. +24 −0 topaz/system.py
@@ -1,7 +1,6 @@
from __future__ import absolute_import

import os
import subprocess

from rpython.rlib import jit
from rpython.rlib.objectmodel import specialize
@@ -10,7 +9,7 @@
from topaz.error import RubyError, print_traceback
from topaz.objects.exceptionobject import W_SystemExit
from topaz.objspace import ObjectSpace
from topaz.system import IS_WINDOWS, IS_64BIT
from topaz.system import IS_WINDOWS, RUBY_DESCRIPTION


USAGE = "\n".join([
@@ -42,11 +41,6 @@
""
])
COPYRIGHT = "topaz - Copyright (c) Alex Gaynor and individual contributors\n"
RUBY_REVISION = subprocess.check_output([
"git",
"--git-dir", os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, ".git"),
"rev-parse", "--short", "HEAD"
]).rstrip()

if IS_WINDOWS:
def WinStdinStream():
@@ -128,13 +122,7 @@ def _parse_argv(space, argv):
elif arg == "--copyright":
raise ShortCircuitError(COPYRIGHT)
elif arg == "--version":
raise ShortCircuitError("%s\n" % space.str_w(
space.send(
space.w_object,
"const_get",
[space.newstr_fromstr("RUBY_DESCRIPTION")]
)
))
raise ShortCircuitError("%s\n" % RUBY_DESCRIPTION)
elif arg == "-v":
flag_globals_w["$-v"] = space.w_true
flag_globals_w["$VERBOSE"] = space.w_true
@@ -221,23 +209,6 @@ def _parse_argv(space, argv):


def _entry_point(space, argv):
if IS_WINDOWS:
system = "Windows"
cpu = "x86_64" if IS_64BIT else "i686"
else:
system, _, _, _, cpu = os.uname()
platform = "%s-%s" % (cpu, system.lower())
engine = "topaz"
version = "2.4.0"
patchlevel = 0
description = "%s (ruby-%sp%d) (git rev %s) [%s]" % (engine, version, patchlevel, RUBY_REVISION, platform)
space.set_const(space.w_object, "RUBY_ENGINE", space.newstr_fromstr(engine))
space.set_const(space.w_object, "RUBY_VERSION", space.newstr_fromstr(version))
space.set_const(space.w_object, "RUBY_PATCHLEVEL", space.newint(patchlevel))
space.set_const(space.w_object, "RUBY_PLATFORM", space.newstr_fromstr(platform))
space.set_const(space.w_object, "RUBY_DESCRIPTION", space.newstr_fromstr(description))
space.set_const(space.w_object, "RUBY_REVISION", space.newstr_fromstr(RUBY_REVISION))

try:
(
flag_globals_w,
@@ -275,7 +246,7 @@ def _entry_point(space, argv):
space.set_const(space.w_object, "ARGV", space.newarray(argv_w))
explicitly_verbose = space.is_true(flag_globals_w["$-v"])
if explicitly_verbose:
os.write(1, "%s\n" % description)
os.write(1, "%s\n" % RUBY_DESCRIPTION)
for varname, w_value in flag_globals_w.iteritems():
space.globals.set(space, varname, w_value)

@@ -284,6 +284,25 @@ def setup(self, executable):
self.send(self.w_load_path, "unshift", [self.newstr_fromstr(lib_path)])
self.load_kernel(kernel_path)

self.set_const(
self.w_object,
"RUBY_ENGINE", self.newstr_fromstr(system.RUBY_ENGINE))
self.set_const(
self.w_object,
"RUBY_VERSION", self.newstr_fromstr(system.RUBY_VERSION))
self.set_const(
self.w_object,
"RUBY_PATCHLEVEL", self.newint(system.RUBY_PATCHLEVEL))
self.set_const(
self.w_object,
"RUBY_PLATFORM", self.newstr_fromstr(system.RUBY_PLATFORM))
self.set_const(
self.w_object,
"RUBY_DESCRIPTION", self.newstr_fromstr(system.RUBY_DESCRIPTION))
self.set_const(
self.w_object,
"RUBY_REVISION", self.newstr_fromstr(system.RUBY_REVISION))

def load_kernel(self, kernel_path):
self.send(
self.w_kernel,
@@ -1,9 +1,33 @@
import sys
import os
import platform
import subprocess

IS_POSIX = os.name == "posix"
IS_WINDOWS = os.name == "nt"
IS_LINUX = "linux" in sys.platform
IS_64BIT = "64bit" in platform.architecture()[0]
IS_CYGWIN = "cygwin" == sys.platform

try:
RUBY_REVISION = subprocess.check_output([
"git",
"--git-dir", os.path.join(os.path.dirname(
os.path.abspath(__file__)), os.pardir, ".git"),
"rev-parse", "--short", "HEAD"
]).rstrip()
except subprocess.CalledProcessError:
RUBY_REVISION = "unknown"

if IS_WINDOWS:
os_name = "Windows"
cpu = "x86_64" if IS_64BIT else "i686"
else:
os_name, _, _, _, cpu = os.uname()

RUBY_PLATFORM = "%s-%s" % (cpu, os_name.lower())
RUBY_ENGINE = "topaz"
RUBY_VERSION = "2.4.0"
RUBY_PATCHLEVEL = 0
RUBY_DESCRIPTION = "%s (ruby-%sp%d) (git rev %s) [%s]" % (
RUBY_ENGINE, RUBY_VERSION, RUBY_PATCHLEVEL, RUBY_REVISION, RUBY_PLATFORM)

0 comments on commit 82ff449

Please sign in to comment.