diff --git a/common.gypi b/common.gypi index 1dd7fdcca0..3a659f8e30 100755 --- a/common.gypi +++ b/common.gypi @@ -2,6 +2,7 @@ 'variables': { 'target_arch%': 'x64', # configure with --dest-cpu 'target_os%': 'none', # configure with --tizen + 'revision%': 'N/A', # configure if available 'build_host%': '<(OS)', 'asan%': '0', }, diff --git a/configure.py b/configure.py index 075a6ebb4a..57ec99779e 100755 --- a/configure.py +++ b/configure.py @@ -42,6 +42,25 @@ def read_node_config_gypi(config_gypi_path): content = f.read() return ast.literal_eval(content) +def get_git_hash(): + git_rev = "" + git_diff = "" + + try: + subprocess.call( + ["git", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL + ) + query_git_rev = "echo $(git log --pretty=format:'%h' -n 1)" + query_git_diff = "echo $(git diff --quiet --exit-code || echo +)" + git_rev = ( + subprocess.check_output(query_git_rev, shell=True).decode("utf-8").strip() + ) + git_diff = ( + subprocess.check_output(query_git_diff, shell=True).decode("utf-8").strip() + ) + except Exception: + git_rev = "N/A" + return str(git_rev + git_diff if git_rev != ("" or "N/A") else "N/A") def lwnode_gyp_opts(opts): '''Returns GYP options.''' @@ -60,6 +79,7 @@ def lwnode_gyp_opts(opts): # definitions (used: shim && escargot) args += ['-Dtarget_os=' + ('tizen' if opts.tizen else 'linux')] args += ['-Dprofile=' + str(opts.profile)] if opts.tizen else [] + args += ['-Drevision=' + opts.revision] # definitions (used: escargot) args += ['-Descargot_build_mode=' + ('debug' if opts.debug else 'release')] @@ -71,6 +91,9 @@ def lwnode_gyp_opts(opts): def main(opts): + if opts.revision == "": + opts.revision = get_git_hash() + # 1. create `NODE_DIR/config.gypi` configure_path = os.path.join(NODE_DIR, 'configure.py') @@ -97,6 +120,7 @@ def main(opts): o['javascript_engine'] = 'escargot' o['lwnode_external_builtin_script'] = b(not opts.without_external_builtins) o['lwnode_reload_script'] = b(not opts.without_reload_script) + o['lwnode_revision'] = opts.revision v = config['variables'] print_verbose('* extends config.gypi', opts.verbose) @@ -148,6 +172,13 @@ def setupCLIOptions(parser): 'Flags that allow you to control LWNode.js build options', ) + lwnode_optgroup.add_option( + '--revision', + dest="revision", + help="Set a revision string", + default="", + ) + lwnode_optgroup.add_option( '--tizen', action='store_true', diff --git a/deps/node/src/lwnode/aul-event-receiver.cc b/deps/node/src/lwnode/aul-event-receiver.cc index f359c890f9..a5a1f654ea 100644 --- a/deps/node/src/lwnode/aul-event-receiver.cc +++ b/deps/node/src/lwnode/aul-event-receiver.cc @@ -99,7 +99,7 @@ bool AULEventReceiver::start(int argc, char* argv[]) { initLoggerOutput(true, appid_); LWNODE_DEV_LOG(parsed_bundle); - LWNODE_DEV_LOG("appid: ", appid_); + LWNODE_DEV_LOG("appid:", appid_); char* path = app_get_resource_path(); if (uv_chdir(path) != 0) { @@ -110,11 +110,13 @@ bool AULEventReceiver::start(int argc, char* argv[]) { free(path); assert(!appid_.empty()); - return isEventReceiverRunning(); + } else { + initLoggerOutput(false); + assert(appid_.empty()); } - initLoggerOutput(false); - assert(appid_.empty()); + LWNODE_DEV_LOG("revision:", LWNODE_REVISION); + return isEventReceiverRunning(); } #endif diff --git a/docs/Build.md b/docs/Build.md index 8c191fac4d..1340d9bbd8 100644 --- a/docs/Build.md +++ b/docs/Build.md @@ -77,9 +77,31 @@ $ gbs -c .github/gbs.conf build -A arm7l --include-all --incremental Use option with `--define ' '`. For example, If you want to build to static type, -```sh +```sh $ gbs -c .github/gbs.conf build -A arm7l --include-all --incremental --define 'lib_type static' ``` Options list: `lib_type` : shared(default)|static + +#### Building a package with a revision string + +By default, lwnode binary contains revision information based on a git commit +id. This requires `git` in your build environment, but it is not available in +GBS. In this case, you can manually set revision information using the following +option. + +```console +$ gbs ... --define 'revision $(git rev-parse --short HEAD)' +``` + +The following also indicates whether the git repository is modifed or not. +```console +$ gbs ... --define 'revision $(git rev-parse --short HEAD)$(git diff --quiet --exit-code || echo +)' +``` + +The revision information can also be found in `process.config`, as shown below. + +```console +$ lwnode -e 'console.log(process.config.variables.lwnode_revision)' +``` diff --git a/escargotshim.gyp b/escargotshim.gyp index cb887cc416..5b0eecef62 100755 --- a/escargotshim.gyp +++ b/escargotshim.gyp @@ -89,6 +89,7 @@ 'direct_dependent_settings': { 'defines': [ 'LWNODE', + 'LWNODE_REVISION="<(revision)"', ], 'include_dirs': [ 'src/api/utils/logger', diff --git a/packaging/lwnode.spec b/packaging/lwnode.spec index e7864120a6..0c720b7004 100644 --- a/packaging/lwnode.spec +++ b/packaging/lwnode.spec @@ -132,7 +132,7 @@ echo $CFLAGS %endif # building lwnode executable - ./configure.py --tizen --verbose \ + ./configure.py --tizen --verbose --revision='%{?revision}' \ --nopt --dest-cpu='%{tizen_arch}' \ %{?lib_type_config} %{?asan_config} \ %{?external_libs_config} %{?jsengine_config}