Bug 1898258 - Add and document mach gen-uuid. r=smaug

The website in our docs no longer works for $reasons, this is a direct
port to python.

Differential Revision: https://phabricator.services.mozilla.com/D211219
This commit is contained in:
Emilio Cobos Álvarez 2024-05-22 14:52:20 +00:00
parent 4a93fb1a5f
commit 8fa7c1f7cf
4 changed files with 28 additions and 6 deletions

View file

@ -19,3 +19,23 @@ def gen_use_counter_metrics(command_context):
from usecounters import gen_use_counter_metrics
return gen_use_counter_metrics()
@Command(
"gen-uuid",
category="misc",
description="Generate a uuid suitable for use in xpidl files and/or in C++",
)
def gen_uuid(command_context):
import uuid
uuid_str = str(uuid.uuid4())
print(uuid_str)
print()
stuff = uuid_str.split("-")
print(f"{{ 0x{stuff[0]}, 0x{stuff[1]}, 0x{stuff[2]}, \\")
print(f" {{ 0x{stuff[3][0:2]}, 0x{stuff[3][2:4]}, ", end="")
print(f"0x{stuff[4][0:2]}, 0x{stuff[4][2:4]}, ", end="")
print(f"0x{stuff[4][4:6]}, 0x{stuff[4][6:8]}, ", end="")
print(f"0x{stuff[4][8:10]}, 0x{stuff[4][10:12]} }} }}")

View file

@ -109,6 +109,7 @@ MACH_COMMANDS = {
"geckoview-junit": MachCommandReference(
"testing/mochitest/mach_commands.py", ["test"]
),
"gen-uuid": MachCommandReference("dom/base/mach_commands.py"),
"gen-use-counter-metrics": MachCommandReference("dom/base/mach_commands.py"),
"generate-test-certs": MachCommandReference(
"security/manager/tools/mach_commands.py"

View file

@ -71,8 +71,8 @@ Next write the initial :code:`.idl` file: :code:`path/to/nsIComponentName.idl`
// `scriptable` designates that this object will be used with JavaScript
// `uuid` The example below uses a UUID with all Xs. Replace the Xs with
// your own UUID generated here:
// http://mozilla.pettay.fi/cgi-bin/mozuuid.pl
// your own UUID generated with `mach gen-uuid`, `uuidgen`, or
// https://mozilla.pettay.fi/uuidgen.html
/**
* Make sure to document your interface.
@ -219,8 +219,8 @@ The easiest way to do that is to copy from ``<objdir>/xpcom/components/services.
Classes = [
{
# This CID is the ID for component entries, and needs a separate UUID from
# the .idl file. Replace the Xs with a uuid from:
# http://mozilla.pettay.fi/cgi-bin/mozuuid.pl
# the .idl file. Replace the Xs with a uuid from `mach gen-uuid`,
# `uuidgen`, or https://mozilla.pettay.fi/uuidgen.html
'cid': '{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}',
'interfaces': ['nsIComponentName'],

View file

@ -178,8 +178,9 @@ The internal unique identifier for the interface. it must be unique, and the
uuid must be generated when creating the interface. After that, it doesn't need
to be changed any more.
Online tools such as http://mozilla.pettay.fi/cgi-bin/mozuuid.pl can help
generate UUIDs for new interfaces.
``mach gen-uuid``, a cli tool like ``uuidgen``, or an online tool like
https://mozilla.pettay.fi/mozuuid.html can help generate UUIDs for new
interfaces.
``builtinclass``
````````````````