Skip to content

Commit 0b6ec6d

Browse files
author
Beatriz Rizental
authored
Merge pull request #375 from brizental/1707896-nice-qt
Bug 1707896 - Make the Qt package a QML module
2 parents 2b3f637 + 685eac1 commit 0b6ec6d

File tree

15 files changed

+168
-37
lines changed

15 files changed

+168
-37
lines changed

.circleci/config.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ jobs:
135135
python3 -m venv venv
136136
source venv/bin/activate
137137
pip install -r requirements.txt
138-
glean_parser translate metrics.yaml pings.yaml -f javascript -o generated --option platform=qt
138+
glean_parser translate metrics.yaml pings.yaml -f javascript -o generated \
139+
--option platform=qt --option version=0.14
139140
140141
sudo apt-get install xvfb
141142
xvfb-run python main.py &> qml.log &
@@ -208,8 +209,8 @@ jobs:
208209
# Attach Qt build to release
209210
npm --prefix ./glean install
210211
npm --prefix ./glean run build:qt
211-
cp glean/dist/glean.js glean/dist/glean_js-${CIRCLE_TAG}-qt.js
212-
./ghr -u mozilla -replace ${CIRCLE_TAG} glean/dist/glean_js-${CIRCLE_TAG}-qt.js
212+
tar -zcvf "glean/dist/glean_js-${CIRCLE_TAG}-qt.tar.gz" glean/dist/qt
213+
./ghr -u mozilla -replace ${CIRCLE_TAG} glean/dist/glean_js-${CIRCLE_TAG}-qt.tar.gz
213214
214215
workflows:
215216
version: 2

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.14.1...main)
44

55
* [#389](https://github.com/mozilla/glean.js/pull/389): BUGFIX: Make sure to submit a `deletion-request` ping before clearing data when toggling upload.
6+
* [#375](https://github.com/mozilla/glean.js/pull/375): Release Glean.js for Qt as a QML module.
67

78
# v0.14.1 (2021-05-21)
89

bin/prepare-qml-module.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
set -eo pipefail
8+
9+
WORKSPACE_ROOT="$( cd "$(dirname "$0")/.." ; pwd -P )"
10+
11+
# Get @mozilla/glean current version without the patch version.
12+
# Qt import paths may only have major and minor version.
13+
GLEAN_VERSION=$(node -p -e "require('${WORKSPACE_ROOT}/glean/package.json').version.split('.').reverse().slice(1).reverse().join('.')")
14+
15+
# Create the qmldir file
16+
FILE=glean/dist/qt/org/mozilla/Glean/qmldir
17+
touch "${WORKSPACE_ROOT}/${FILE}"
18+
{
19+
echo module org.mozilla.Glean
20+
echo Glean $GLEAN_VERSION glean.js
21+
} >> "${WORKSPACE_ROOT}/${FILE}"
22+
23+
# Add the glean.js file to the final module
24+
cp "${WORKSPACE_ROOT}/glean/src/index/qt.js" "${WORKSPACE_ROOT}/glean/dist/qt/org/mozilla/Glean/glean.js"

bin/prepare-release.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,32 @@ run $SED -i.bak -E \
113113
"${WORKSPACE_ROOT}/${FILE}"
114114
run rm "${WORKSPACE_ROOT}/${FILE}.bak"
115115

116+
### Qt sample app ###
117+
# Qt changes are necessary because QML requires that you add
118+
# version number along with the import statements.
119+
120+
# This gets the version string without the patch version.
121+
GLEAN_VERSION_FOR_QML=$(node -p -e "'${NEW_VERSION}'.split('.').reverse().slice(1).reverse().join('.')")
122+
123+
FILE=samples/qt-qml-app/main.qml
124+
run $SED -i.bak -E \
125+
-e "s/import org.mozilla.Glean [0-9a-z.-]+/import org.mozilla.Glean \"${GLEAN_VERSION_FOR_QML}\";/" \
126+
-e "s/import generated [0-9a-z.-]+/import generated \"${GLEAN_VERSION_FOR_QML}\";/" \
127+
"${WORKSPACE_ROOT}/${FILE}"
128+
run rm "${WORKSPACE_ROOT}/${FILE}.bak"
129+
130+
FILE=samples/qt-qml-app/README.md
131+
run $SED -i.bak -E \
132+
-e "s/--option platform=qt --option version=[0-9a-z.-]+/--option platform=qt --option version=\"${GLEAN_VERSION_FOR_QML}\";/" \
133+
"${WORKSPACE_ROOT}/${FILE}"
134+
run rm "${WORKSPACE_ROOT}/${FILE}.bak"
135+
136+
FILE=.circleci/config.yml
137+
run $SED -i.bak -E \
138+
-e "s/--option platform=qt --option version=[0-9a-z.-]+/--option platform=qt --option version=\"${GLEAN_VERSION_FOR_QML}\";/" \
139+
"${WORKSPACE_ROOT}/${FILE}"
140+
run rm "${WORKSPACE_ROOT}/${FILE}.bak"
141+
116142
echo "Everything prepared for v${NEW_VERSION}"
117143
echo
118144
echo "Changed files:"

glean/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
venv
33
node_modules
4+
qt.js

glean/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"build:webext:lib": "tsc -p ./tsconfig/webext/index.json",
5252
"build:webext:types": "tsc -p ./tsconfig/webext/types.json",
5353
"build:webext": "rm -rf dist/webext && run-s build:webext:lib build:webext:types",
54-
"build:qt": "webpack --config webpack.config.qt.js --mode production",
54+
"build:qt": "rm -rf dist/qt && webpack --config webpack.config.qt.js --mode production && ../bin/prepare-qml-module.sh",
5555
"build:docs": "rm -rf dist/docs && typedoc src/ --out dist/docs --tsconfig tsconfig/docs.json --theme minimal",
5656
"publish:docs": "NODE_DEBUG=gh-pages gh-pages --dotfiles --message \"[skip ci] Updates\" --dist dist/docs",
5757
"prepublishOnly": "cp ../README.md ./README.md && run-s build:cli build:webext",

glean/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { promisify } from "util";
1515
const VIRTUAL_ENVIRONMENT_DIR = ".venv";
1616

1717
// The version of glean_parser to install from PyPI.
18-
const GLEAN_PARSER_VERSION = "3.2.0";
18+
const GLEAN_PARSER_VERSION = "3.5.0";
1919

2020
// This script runs a given Python module as a "main" module, like
2121
// `python -m module`. However, it first checks that the installed

glean/src/index/qt.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
// This file is the actual entry point file for Glean.js in QML, that users will interact with.
6+
//
7+
// I was not able to figure out a way to simply use the Webpack generated file to
8+
// be the entry point in Qt, because of the unusual syntax allowed in Qt Javascript.
9+
// Thus, we compile the Glean.js library normaly into the `glean.lib.js` file and then
10+
// we have this file which interacts opaquely with the Webpack generated one.
11+
//
12+
// **All functions and variables defined here are public.**
13+
14+
.pragma library
15+
16+
.import "glean.lib.js" as Glean
17+
18+
/**
19+
* Initialize Glean. This method should only be called once, subsequent calls will be no-op.
20+
*
21+
* @param applicationId The application ID (will be sanitized during initialization).
22+
* @param uploadEnabled Determines whether telemetry is enabled.
23+
* If disabled, all persisted metrics, events and queued pings (except
24+
* first_run_date) are cleared.
25+
* @param config Glean configuration options.
26+
*/
27+
function initialize(applicationId, uploadEnabled, config) {
28+
Glean.Glean.default.initialize(applicationId, uploadEnabled, config);
29+
}
30+
31+
/**
32+
* Sets whether upload is enabled or not.
33+
*
34+
* When uploading is disabled, metrics aren't recorded at all and no data is uploaded.
35+
*
36+
* When disabling, all pending metrics, events and queued pings are cleared.
37+
*
38+
* When enabling, the core Glean metrics are recreated.
39+
*
40+
* If the value of this flag is not actually changed, this is a no-op.
41+
*
42+
* If Glean has not been initialized yet, this is also a no-op.
43+
*
44+
* @param flag When true, enable metric collection.
45+
*/
46+
function setUploadEnabled(flag) {
47+
Glean.Glean.default.setUploadEnabled(flag);
48+
}
49+
50+
/**
51+
* Sets the `logPings` flag.
52+
*
53+
* When this flag is `true` pings will be logged
54+
* to the console right before they are collected.
55+
*
56+
* @param flag Whether or not to log pings.
57+
*/
58+
function setLogPings(flag) {
59+
Glean.Glean.default.setLogPings(flag);
60+
}
61+
62+
/**
63+
* Sets the `debugViewTag` debug option.
64+
*
65+
* When this property is set, all subsequent outgoing pings will include the `X-Debug-ID` header
66+
* which will redirect them to the ["Ping Debug Viewer"](https://debug-ping-preview.firebaseapp.com/).
67+
*
68+
* To unset the `debugViewTag` call `Glean.unsetDebugViewTag();
69+
*
70+
* @param value The value of the header.
71+
* This value must satify the regex `^[a-zA-Z0-9-]{1,20}$` otherwise it will be ignored.
72+
*/
73+
function setDebugViewTag(value) {
74+
Glean.Glean.default.setDebugViewTag(value);
75+
}
76+
77+
/**
78+
* Sets the `sourceTags` debug option.
79+
*
80+
* Ping tags will show in the destination datasets, after ingestion.
81+
*
82+
* Note** Setting `sourceTags` will override all previously set tags.
83+
*
84+
* To unset the `sourceTags` call `Glean.unsetSourceTags();
85+
*
86+
* @param value A vector of at most 5 valid HTTP header values.
87+
* Individual tags must match the regex: "[a-zA-Z0-9-]{1,20}".
88+
*/
89+
function setSourceTags(value) {
90+
Glean.Glean.default.setSourceTags(value);
91+
}
92+
93+
const _private = Glean.Glean.default._private;

glean/src/index/qt.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,10 @@ export default {
2323
/**
2424
* Initialize Glean. This method should only be called once, subsequent calls will be no-op.
2525
*
26-
* # Note
27-
*
28-
* Before this method is called Glean will not be able to upload pings or record metrics,
29-
* all such operations will be no-op.
30-
*
31-
* This is _not_ the way glean-core deals with this. It will record tasks performed before init
32-
* and flush them on init. We have a bug to figure out how to do that for Glean.js, Bug 1687491.
33-
*
3426
* @param applicationId The application ID (will be sanitized during initialization).
3527
* @param uploadEnabled Determines whether telemetry is enabled.
36-
* If disabled, all persisted metrics, events and queued pings (except
37-
* first_run_date) are cleared.
28+
* If disabled, all persisted metrics, events and queued pings (except
29+
* first_run_date) are cleared.
3830
* @param config Glean configuration options.
3931
*/
4032
initialize(

glean/src/index/webext.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ export default {
1111
/**
1212
* Initialize Glean. This method should only be called once, subsequent calls will be no-op.
1313
*
14-
* # Note
15-
*
16-
* Before this method is called Glean will not be able to upload pings or record metrics,
17-
* all such operations will be no-op.
18-
*
19-
* This is _not_ the way glean-core deals with this. It will record tasks performed before init
20-
* and flush them on init. We have a bug to figure out how to do that for Glean.js, Bug 1687491.
21-
*
2214
* @param applicationId The application ID (will be sanitized during initialization).
2315
* @param uploadEnabled Determines whether telemetry is enabled.
2416
* If disabled, all persisted metrics, events and queued pings (except

0 commit comments

Comments
 (0)