@geastack/cli 0.1.85 → 0.1.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/cli",
3
- "version": "0.1.85",
3
+ "version": "0.1.86",
4
4
  "description": "Command-line front door for GeaStack apps, targets, and local toolchains.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -6,7 +6,7 @@ import { loadChipCatalogFromDir, writeCustomTarget } from '../boards/custom-targ
6
6
  import { CliError, ExitCode, fail } from '../errors.mjs'
7
7
  import { appCmakeMeta, appCmakeDefines, appCmakeLdFragments, appTargetConfig, appTargetPaths } from '../manifest.mjs'
8
8
  import { quietSteps, runQuiet } from '../run.mjs'
9
- import { resolveAppCapabilities } from './capabilities.mjs'
9
+ import { resolveAppCapabilities, withRendererFeatureDefines } from './capabilities.mjs'
10
10
  import { activateEspIdf, idfPyCommand } from './idf-env.mjs'
11
11
  import { Sdkconfig, prepareBuildLocalSdkconfig } from './sdkconfig.mjs'
12
12
  import { writePartitionTable } from './partitions-from-manifest.mjs'
@@ -416,7 +416,7 @@ function preparePartitions(app, config, buildDir, targetId) {
416
416
  // `set(... CACHE STRING ...)`, so a -D of the same name, which exists before
417
417
  // the board's CMakeLists runs, wins without the board knowing about apps.
418
418
  const cssDpr = cssDevicePixelRatioLiteral(app.cssDevicePixelRatio)
419
- const appDefines = [appCmakeDefines(app), cssDpr && `GEA_EMBEDDED_CSS_LAYOUT_DEVICE_PIXEL_RATIO=${cssDpr}`]
419
+ const appDefines = [withRendererFeatureDefines(appCmakeDefines(app), capabilities.features), cssDpr && `GEA_EMBEDDED_CSS_LAYOUT_DEVICE_PIXEL_RATIO=${cssDpr}`]
420
420
  .filter(Boolean)
421
421
  .join(';')
422
422
  const esp32Config = appEsp32Config
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
 
4
4
  import { ExitCode, fail } from '../errors.mjs'
5
5
  import { exists } from '../fs-utils.mjs'
6
+ import { withNativeCssFeatures } from './native-css-features.mjs'
6
7
 
7
8
  // What the firmware must link for this app. The compiler analyses the entry
8
9
  // (with the gea plugin) and reports the host bindings the program reaches;
@@ -10,6 +11,35 @@ import { exists } from '../fs-utils.mjs'
10
11
  // something actually uses them.
11
12
  const networkBindings = ['wifi', 'fetch', 'http', 'websocket', 'rtc']
12
13
 
14
+ const cssFeatureDefines = [
15
+ ['css-transforms', 'GEA_CSS_TRANSFORMS'],
16
+ ['css-grid', 'GEA_CSS_GRID'],
17
+ ['css-floats', 'GEA_CSS_FLOATS'],
18
+ ['css-writing-mode', 'GEA_CSS_WRITING_MODE'],
19
+ ['css-border-relief', 'GEA_CSS_BORDER_RELIEF']
20
+ ]
21
+
22
+ const rendererFeatureDefines = [
23
+ ['renderer-circles', 'GEA_EMBEDDED_RENDERER_CIRCLES'],
24
+ ['renderer-transforms', 'GEA_EMBEDDED_RENDERER_TRANSFORMS'],
25
+ ['renderer-linear-gradients', 'GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS'],
26
+ ['renderer-radial-gradients', 'GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS']
27
+ ]
28
+
29
+ export function withRendererFeatureDefines(defines, features) {
30
+ // An older plugin knows nothing about renderer features. Absence without the
31
+ // version marker is not proof of unreachability: retain engine defaults.
32
+ const generatedNames = new Set([...rendererFeatureDefines, ...cssFeatureDefines].map(([, name]) => name))
33
+ const result = defines.split(';').filter((define) => define && !generatedNames.has(define.split('=')[0]))
34
+ if (features.includes('renderer-analysis-v1')) {
35
+ for (const [feature, name] of rendererFeatureDefines) result.push(`${name}=${features.includes(feature) ? 1 : 0}`)
36
+ }
37
+ if (features.includes('css-analysis-v1')) {
38
+ for (const [feature, name] of cssFeatureDefines) result.push(`${name}=${features.includes(feature) ? 1 : 0}`)
39
+ }
40
+ return result.join(';')
41
+ }
42
+
13
43
  export function parseAnalysis(output) {
14
44
  const bindings = output.match(/^bindings=(.*)$/m)?.[1]?.split(';').filter(Boolean) ?? []
15
45
  const features = output.match(/^features=(.*)$/m)?.[1]?.split(';').filter(Boolean) ?? []
@@ -41,7 +71,7 @@ export function analyzeApp(ctx, app, { env = ctx.env || process.env } = {}) {
41
71
  export function resolveAppCapabilities(ctx, app, options = {}) {
42
72
  const analysis = analyzeApp(ctx, app, options)
43
73
  const bindings = new Set(analysis.bindings)
44
- const features = new Set(analysis.features)
74
+ const features = new Set(withNativeCssFeatures(app, analysis.features))
45
75
  const manifestBleOta = manifestRequestsBleOta(app.packageJson)
46
76
  return {
47
77
  network: networkBindings.some((binding) => bindings.has(binding)) || features.has('https'),
@@ -0,0 +1,81 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { resolveAppSourcePath } from '../manifest.mjs'
4
+
5
+ const families = ['css-transforms', 'css-grid', 'css-floats', 'css-writing-mode', 'css-border-relief']
6
+ const sourceExtension = /\.(?:c|cc|cpp|cxx|h|hh|hpp|hxx|S)$/
7
+ const ignored = new Set(['.git', '.gea', 'node_modules', 'build', 'dist', '.build', '.venv'])
8
+ const privateUiHeader = /(?:^|\/)(?:node(?:_model|_lifecycle)?|tree(?:_internal|_state)?|style(?:_values)?|document|internal|view_element|text_element)\.h$/
9
+
10
+ export function nativeCssSourceNeedsSupport(text) {
11
+ // Native code using the mutable UI API can pass computed property names or
12
+ // values at runtime. Retain all CSS automatically in that case. Read-only
13
+ // inspection has a distinct header and exposes no mutable node/style data.
14
+ if (/#\s*include\s+(?![<"])[A-Za-z_]/.test(text)) return true
15
+ for (const match of text.matchAll(/#\s*include\s*[<"]([^>"\n]+)[>"]/g)) {
16
+ const header = match[1].replaceAll('\\', '/')
17
+ if (header.endsWith('ui/tree_inspection.h')) continue
18
+ if (header.startsWith('ui/') || privateUiHeader.test(header)) return true
19
+ }
20
+ return /\b(?:ComputedStyle|StyleSheet|CssCompiledValue|CssDeclarationId)\b|\bProperty\s*::|(?:\.|->)\s*(?:style|cssText)\b|\b(?:setProperty|applyTransformComponentsFast|applyTransformSlotsFast)\s*\(/.test(text)
21
+ }
22
+
23
+ export function withNativeCssFeatures(app, features) {
24
+ if (!features.includes('css-analysis-v1')) return features
25
+ const sources = app.nativeSources || []
26
+ const components = app.targetConfig?.esp32?.componentDirs || []
27
+ if (!sources.length && !components.length) return features
28
+ const retain = () => [...new Set([...features, ...families])].sort()
29
+ const root = path.resolve(app.root)
30
+ const headers = new Map()
31
+ const seen = new Set()
32
+ const pending = []
33
+ let opaque = false
34
+ function walk(dir, collectSources = false) {
35
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
36
+ const file = path.join(dir, entry.name)
37
+ if (entry.isDirectory()) {
38
+ if (!ignored.has(entry.name)) walk(file, collectSources)
39
+ } else if (sourceExtension.test(entry.name)) {
40
+ if (/\.(?:h|hh|hpp|hxx)$/.test(entry.name)) {
41
+ const matches = headers.get(entry.name) || []
42
+ matches.push(file)
43
+ headers.set(entry.name, matches)
44
+ }
45
+ if (collectSources) pending.push(file)
46
+ } else if (collectSources && /\.(?:a|so|dylib|lib)$/.test(entry.name)) opaque = true
47
+ }
48
+ }
49
+ try {
50
+ walk(root)
51
+ for (const source of sources) {
52
+ const resolved = resolveAppSourcePath(root, source)
53
+ if (!resolved || !resolved.startsWith(root + path.sep)) return retain()
54
+ pending.push(resolved)
55
+ }
56
+ for (const component of components) {
57
+ const dir = path.resolve(root, component)
58
+ if (!dir.startsWith(root + path.sep)) return retain()
59
+ walk(dir, true)
60
+ }
61
+ while (pending.length && !opaque) {
62
+ const file = pending.pop()
63
+ if (seen.has(file)) continue
64
+ seen.add(file)
65
+ const text = fs.readFileSync(file, 'utf8')
66
+ if (nativeCssSourceNeedsSupport(text)) return retain()
67
+ // Follow app headers, including headers provided by another component's
68
+ // include directory. ESP-IDF and C/C++ platform headers do not depend on
69
+ // the UI engine. An external native package is opaque above.
70
+ for (const match of text.matchAll(/#\s*include\s*[<"]([^>"\n]+)[>"]/g)) {
71
+ const header = match[1]
72
+ const local = path.resolve(path.dirname(file), header)
73
+ if (fs.existsSync(local)) pending.push(local)
74
+ else for (const candidate of headers.get(path.basename(header)) || []) pending.push(candidate)
75
+ }
76
+ }
77
+ } catch {
78
+ return retain()
79
+ }
80
+ return opaque ? retain() : features
81
+ }