Skip to content

Commit

Permalink
feat: support lwnode revision string
Browse files Browse the repository at this point in the history
Signed-off-by: Daeyeon Jeong <[email protected]>
  • Loading branch information
daeyeon committed Apr 2, 2024
1 parent 1a1cdff commit b0acf9b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
31 changes: 31 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "N/A"
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.'''
Expand All @@ -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')]
Expand All @@ -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')

Expand All @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 6 additions & 4 deletions deps/node/src/lwnode/aul-event-receiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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) {
Expand All @@ -107,11 +107,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
Expand Down
19 changes: 18 additions & 1 deletion docs/Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,26 @@ $ gbs -c .github/gbs.conf build -A arm7l --include-all --incremental
Use option with `--define '<option_key> <option_value>'`.

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 revision information can also be found in `process.config`, as shown below.

```console
$ lwnode -e 'console.log(process.config.variables.lwnode_revision)'
```
1 change: 1 addition & 0 deletions escargotshim.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
'direct_dependent_settings': {
'defines': [
'LWNODE',
'LWNODE_REVISION="<(revision)"',
],
'include_dirs': [
'src/api/utils/logger',
Expand Down
2 changes: 1 addition & 1 deletion packaging/lwnode.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit b0acf9b

Please sign in to comment.