File: Update.py

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 3,603 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2025 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import requests
import shutil

# This script updates the current directory with parts of the ONNX Runtime headers
# needed in Chromium.

# The ONNX Runtime headers needed in Chromium
onnxruntime_headers = [
    "onnxruntime_c_api.h",
    "onnxruntime_session_options_config_keys.h",
]

# The target revision of ONNX Runtime
revision = "30c682547bdae3e09523614f8e38526e49ca8fbc"
# These headers are extracted from a git repository and versioned by revision
version = "N/A"

base_url = "https://raw.githubusercontent.com/microsoft/onnxruntime"
onnxruntime_headers_path = ["include", "onnxruntime", "core", "session"]

# Source URL for the current revision of ONNX Runtime headers
src_url = "/".join([base_url, revision, *onnxruntime_headers_path])
# License URL for the ONNX Runtime repository
license_url = "/".join([base_url, revision, "LICENSE"])

abs_path = os.path.dirname(os.path.abspath(__file__))

# Delete the src directory
abs_src_dir = os.path.join(abs_path, "src")
if os.path.exists(abs_src_dir):
    shutil.rmtree(abs_src_dir)

# Create the directory for ONNX Runtime headers
include_dir = os.path.join("src", *onnxruntime_headers_path)
abs_include_dir = os.path.join(abs_path, include_dir)
os.makedirs(abs_include_dir)

# Update the ONNX Runtime headers
for header in onnxruntime_headers:
    with open(os.path.join(abs_include_dir, header), "wb") as f:
        file_url = "/".join([src_url, header])
        response = requests.get(file_url)
        if response.status_code != 200:
            raise Exception("Failed to download", file_url)
        f.write(response.content)

# Update the license file
with open(os.path.join(abs_path, "src/LICENSE"), "wb") as f:
    response = requests.get(license_url)
    if response.status_code != 200:
        raise Exception("Failed to download", file_url)
    f.write(response.content)

# Generate the BUILD.gn file

def format_headers(headers):
    formatted_string = '[\n'
    for i in range(len(headers)):
        header = os.path.join(include_dir, headers[i]).replace("\\", "/")
        formatted_string += f'    "{header}",\n'
    formatted_string += '  ]'
    return formatted_string

build_file = '''# Copyright 2025 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This file is generated by Update.py and should not be edited.

# onnxruntime_headers is used by WebNN on Windows.

source_set("onnxruntime_headers") {{
  sources = {sources}

  visibility = [ "//services/webnn/*" ]
}}
'''.format(sources=format_headers(onnxruntime_headers))

with open(os.path.join(abs_path, "BUILD.gn"), "w", newline="\n") as f:
    f.write(build_file)

# Generate the README.chromium file

readme_file = '''Name: Headers for ONNX Runtime C/C++ APIs
Short Name: onnxruntime_headers
URL: https://github.com/microsoft/onnxruntime
Version: {version}
Revision: {revision}
License: MIT
License File: src/LICENSE
Shipped: Yes
Security Critical: Yes

Description:
This folder is a snapshot of part of the ONNX Runtime headers for C/C++
APIs. It is used by WebNN for inference on Windows.

To avoid pulling in unnecessary files this snapshot only contains the
headers that are required by WebNN.

Local Modifications: None

# This file is generated by Update.py and should not be edited.
'''.format(version=version, revision=revision)

with open(os.path.join(abs_path, "README.chromium"), "w", newline="\n") as f:
    f.write(readme_file)