Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
78ae72b0
Unverified
Commit
78ae72b0
authored
Apr 10, 2022
by
Janko Djuric
Committed by
GitHub
Apr 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Add --build-number and --build-name support to web and linux (#100377)
parent
391a39a6
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
103 additions
and
5 deletions
+103
-5
build_info.dart
packages/flutter_tools/lib/src/build_info.dart
+10
-0
linux.dart
...ges/flutter_tools/lib/src/build_system/targets/linux.dart
+19
-1
web.dart
packages/flutter_tools/lib/src/build_system/targets/web.dart
+20
-4
build_linux.dart
packages/flutter_tools/lib/src/commands/build_linux.dart
+2
-0
build_web.dart
packages/flutter_tools/lib/src/commands/build_web.dart
+2
-0
build_web_test.dart
...er_tools/test/commands.shard/hermetic/build_web_test.dart
+25
-0
build_info_test.dart
...ges/flutter_tools/test/general.shard/build_info_test.dart
+4
-0
linux_test.dart
...s/test/general.shard/build_system/targets/linux_test.dart
+5
-0
web_test.dart
...ols/test/general.shard/build_system/targets/web_test.dart
+16
-0
No files found.
packages/flutter_tools/lib/src/build_info.dart
View file @
78ae72b0
...
...
@@ -237,6 +237,10 @@ class BuildInfo {
kFileSystemRoots:
fileSystemRoots
.
join
(
','
),
if
(
fileSystemScheme
!=
null
)
kFileSystemScheme:
fileSystemScheme
!,
if
(
buildName
!=
null
)
kBuildName:
buildName
!,
if
(
buildNumber
!=
null
)
kBuildNumber:
buildNumber
!,
};
}
...
...
@@ -952,6 +956,12 @@ const String kIconTreeShakerFlag = 'TreeShakeIcons';
/// The input key for an SkSL bundle path.
const
String
kBundleSkSLPath
=
'BundleSkSLPath'
;
/// The define to pass build name
const
String
kBuildName
=
'BuildName'
;
/// The define to pass build number
const
String
kBuildNumber
=
'BuildNumber'
;
final
Converter
<
String
,
String
>
_defineEncoder
=
utf8
.
encoder
.
fuse
(
base64
.
encoder
);
final
Converter
<
String
,
String
>
_defineDecoder
=
base64
.
decoder
.
fuse
(
utf8
.
decoder
);
...
...
packages/flutter_tools/lib/src/build_system/targets/linux.dart
View file @
78ae72b0
...
...
@@ -5,6 +5,7 @@
import
'../../artifacts.dart'
;
import
'../../base/file_system.dart'
;
import
'../../build_info.dart'
;
import
'../../convert.dart'
;
import
'../../devfs.dart'
;
import
'../../project.dart'
;
import
'../build_system.dart'
;
...
...
@@ -135,7 +136,7 @@ abstract class BundleLinuxAssets extends Target {
environment
.
buildDir
.
childFile
(
'app.dill'
)
.
copySync
(
outputDirectory
.
childFile
(
'kernel_blob.bin'
).
path
);
}
final
String
versionInfo
=
FlutterProject
.
current
().
getVersionInfo
(
);
final
String
versionInfo
=
getVersionInfo
(
environment
.
defines
);
final
Depfile
depfile
=
await
copyAssets
(
environment
,
outputDirectory
,
...
...
@@ -153,6 +154,23 @@ abstract class BundleLinuxAssets extends Target {
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
}
/// Return json encoded string that contains data about version for package_info
String
getVersionInfo
(
Map
<
String
,
String
>
defines
)
{
final
Map
<
String
,
dynamic
>
versionInfo
=
jsonDecode
(
FlutterProject
.
current
().
getVersionInfo
())
as
Map
<
String
,
dynamic
>;
if
(
defines
.
containsKey
(
kBuildNumber
))
{
versionInfo
[
'build_number'
]
=
defines
[
kBuildNumber
];
}
if
(
defines
.
containsKey
(
kBuildName
))
{
versionInfo
[
'version'
]
=
defines
[
kBuildName
];
}
return
jsonEncode
(
versionInfo
);
}
}
/// A wrapper for AOT compilation that copies app.so into the output directory.
...
...
packages/flutter_tools/lib/src/build_system/targets/web.dart
View file @
78ae72b0
...
...
@@ -341,10 +341,7 @@ class WebReleaseBundle extends Target {
);
}
final
String
versionInfo
=
FlutterProject
.
current
().
getVersionInfo
();
environment
.
outputDir
.
childFile
(
'version.json'
)
.
writeAsStringSync
(
versionInfo
);
createVersionFile
(
environment
,
environment
.
defines
);
final
Directory
outputDirectory
=
environment
.
outputDir
.
childDirectory
(
'assets'
);
outputDirectory
.
createSync
(
recursive:
true
);
final
Depfile
depfile
=
await
copyAssets
(
...
...
@@ -411,6 +408,25 @@ class WebReleaseBundle extends Target {
environment
.
buildDir
.
childFile
(
'web_resources.d'
),
);
}
/// Create version.json file that contains data about version for package_info
void
createVersionFile
(
Environment
environment
,
Map
<
String
,
String
>
defines
)
{
final
Map
<
String
,
dynamic
>
versionInfo
=
jsonDecode
(
FlutterProject
.
current
().
getVersionInfo
())
as
Map
<
String
,
dynamic
>;
if
(
defines
.
containsKey
(
kBuildNumber
))
{
versionInfo
[
'build_number'
]
=
defines
[
kBuildNumber
];
}
if
(
defines
.
containsKey
(
kBuildName
))
{
versionInfo
[
'version'
]
=
defines
[
kBuildName
];
}
environment
.
outputDir
.
childFile
(
'version.json'
)
.
writeAsStringSync
(
jsonEncode
(
versionInfo
));
}
}
/// Static assets provided by the Flutter SDK that do not change, such as
...
...
packages/flutter_tools/lib/src/commands/build_linux.dart
View file @
78ae72b0
...
...
@@ -22,6 +22,8 @@ class BuildLinuxCommand extends BuildSubCommand {
})
:
_operatingSystemUtils
=
operatingSystemUtils
,
super
(
verboseHelp:
verboseHelp
)
{
addCommonDesktopBuildOptions
(
verboseHelp:
verboseHelp
);
usesBuildNumberOption
();
usesBuildNameOption
();
final
String
defaultTargetPlatform
=
(
_operatingSystemUtils
.
hostPlatform
==
HostPlatform
.
linux_arm64
)
?
'linux-arm64'
:
'linux-x64'
;
...
...
packages/flutter_tools/lib/src/commands/build_web.dart
View file @
78ae72b0
...
...
@@ -20,6 +20,8 @@ class BuildWebCommand extends BuildSubCommand {
addTreeShakeIconsFlag
(
enabledByDefault:
false
);
usesTargetOption
();
usesPubOption
();
usesBuildNumberOption
();
usesBuildNameOption
();
addBuildModeFlags
(
verboseHelp:
verboseHelp
,
excludeDebug:
true
);
usesDartDefineOption
();
usesWebRendererOption
();
...
...
packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
View file @
78ae72b0
...
...
@@ -148,6 +148,31 @@ void main() {
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
BuildSystem:
()
=>
TestBuildSystem
.
all
(
BuildResult
(
success:
true
)),
});
testUsingContext
(
'Web build supports build-name and build-number'
,
()
async
{
final
TestWebBuildCommand
buildCommand
=
TestWebBuildCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
buildCommand
);
setupFileSystemForEndToEndTest
(
fileSystem
);
await
runner
.
run
(<
String
>[
'build'
,
'web'
,
'--no-pub'
,
'--build-name=1.2.3'
,
'--build-number=42'
,
]);
final
BuildInfo
buildInfo
=
await
buildCommand
.
webCommand
.
getBuildInfo
(
forcedBuildMode:
BuildMode
.
debug
);
expect
(
buildInfo
.
buildNumber
,
'42'
);
expect
(
buildInfo
.
buildName
,
'1.2.3'
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
fakePlatform
,
FileSystem:
()
=>
fileSystem
,
FeatureFlags:
()
=>
TestFeatureFlags
(
isWebEnabled:
true
),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
BuildSystem:
()
=>
TestBuildSystem
.
all
(
BuildResult
(
success:
true
)),
});
}
void
setupFileSystemForEndToEndTest
(
FileSystem
fileSystem
)
{
...
...
packages/flutter_tools/test/general.shard/build_info_test.dart
View file @
78ae72b0
...
...
@@ -121,6 +121,8 @@ void main() {
codeSizeDirectory:
'foo/code-size'
,
fileSystemRoots:
<
String
>[
'test5'
,
'test6'
],
fileSystemScheme:
'scheme'
,
buildName:
'122'
,
buildNumber:
'22'
);
expect
(
buildInfo
.
toBuildSystemEnvironment
(),
<
String
,
String
>{
...
...
@@ -136,6 +138,8 @@ void main() {
'CodeSizeDirectory'
:
'foo/code-size'
,
'FileSystemRoots'
:
'test5,test6'
,
'FileSystemScheme'
:
'scheme'
,
'BuildName'
:
'122'
,
'BuildNumber'
:
'22'
,
});
});
...
...
packages/flutter_tools/test/general.shard/build_system/targets/linux_test.dart
View file @
78ae72b0
...
...
@@ -100,6 +100,8 @@ void main() {
fileSystem
.
currentDirectory
,
defines:
<
String
,
String
>{
kBuildMode:
'debug'
,
kBuildName:
'2.0.0'
,
kBuildNumber:
'22'
,
},
inputs:
<
String
,
String
>{
kBundleSkSLPath:
'bundle.sksl'
,
...
...
@@ -133,6 +135,9 @@ void main() {
expect
(
output
.
childFile
(
'kernel_blob.bin'
),
exists
);
expect
(
output
.
childFile
(
'AssetManifest.json'
),
exists
);
expect
(
output
.
childFile
(
'version.json'
),
exists
);
final
String
versionFile
=
output
.
childFile
(
'version.json'
).
readAsStringSync
();
expect
(
versionFile
,
contains
(
'"version":"2.0.0"'
));
expect
(
versionFile
,
contains
(
'"build_number":"22"'
));
// SkSL
expect
(
output
.
childFile
(
'io.flutter.shaders.json'
),
exists
);
expect
(
output
.
childFile
(
'io.flutter.shaders.json'
).
readAsStringSync
(),
'{"data":{"A":"B"}}'
);
...
...
packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
View file @
78ae72b0
...
...
@@ -102,6 +102,22 @@ void main() {
expect
(
environment
.
outputDir
.
childFile
(
'version.json'
),
exists
);
}));
test
(
'override version values'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'release'
;
environment
.
defines
[
kBuildName
]
=
'2.0.0'
;
environment
.
defines
[
kBuildNumber
]
=
'22'
;
final
Directory
webResources
=
environment
.
projectDir
.
childDirectory
(
'web'
);
webResources
.
childFile
(
'index.html'
).
createSync
(
recursive:
true
);
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
createSync
();
await
const
WebReleaseBundle
().
build
(
environment
);
final
String
versionFile
=
environment
.
outputDir
.
childFile
(
'version.json'
)
.
readAsStringSync
();
expect
(
versionFile
,
contains
(
'"version":"2.0.0"'
));
expect
(
versionFile
,
contains
(
'"build_number":"22"'
));
}));
test
(
'Base href is created in index.html with given base-href after release build'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'release'
;
environment
.
defines
[
kBaseHref
]
=
'/basehreftest/'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment