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
bf6c4c4a
Unverified
Commit
bf6c4c4a
authored
Jan 07, 2020
by
Jonah Williams
Committed by
GitHub
Jan 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools]web]Add support for --csp mode to build web (#48319)
parent
965ba387
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
2 deletions
+59
-2
web_fs.dart
packages/flutter_tools/lib/src/build_runner/web_fs.dart
+16
-2
web.dart
packages/flutter_tools/lib/src/build_system/targets/web.dart
+6
-0
build_web.dart
packages/flutter_tools/lib/src/commands/build_web.dart
+7
-0
compile.dart
packages/flutter_tools/lib/src/web/compile.dart
+2
-0
build_web_test.dart
...er_tools/test/commands.shard/hermetic/build_web_test.dart
+1
-0
web_test.dart
...ols/test/general.shard/build_system/targets/web_test.dart
+27
-0
No files found.
packages/flutter_tools/lib/src/build_runner/web_fs.dart
View file @
bf6c4c4a
...
...
@@ -150,7 +150,14 @@ class WebFs {
/// Recompile the web application and return whether this was successful.
Future
<
bool
>
recompile
()
async
{
if
(!
_useBuildRunner
)
{
await
buildWeb
(
_flutterProject
,
_target
,
_buildInfo
,
_initializePlatform
,
_dartDefines
);
await
buildWeb
(
_flutterProject
,
_target
,
_buildInfo
,
_initializePlatform
,
_dartDefines
,
false
,
);
return
true
;
}
_client
.
startBuild
();
...
...
@@ -309,7 +316,14 @@ class WebFs {
handler
=
pipeline
.
addHandler
(
proxyHandler
(
'http://localhost:
$daemonAssetPort
/web/'
));
}
}
else
{
await
buildWeb
(
flutterProject
,
target
,
buildInfo
,
initializePlatform
,
dartDefines
);
await
buildWeb
(
flutterProject
,
target
,
buildInfo
,
initializePlatform
,
dartDefines
,
false
,
);
firstBuildCompleter
.
complete
(
true
);
}
...
...
packages/flutter_tools/lib/src/build_system/targets/web.dart
View file @
bf6c4c4a
...
...
@@ -26,6 +26,9 @@ const String kHasWebPlugins = 'HasWebPlugins';
/// Valid values are O1 (lowest, profile default) to O4 (highest, release default).
const
String
kDart2jsOptimization
=
'Dart2jsOptimization'
;
/// Whether to disable dynamic generation code to satisfy csp policies.
const
String
kCspMode
=
'cspMode'
;
/// Generates an entry point for a web target.
class
WebEntrypointTarget
extends
Target
{
const
WebEntrypointTarget
();
...
...
@@ -146,6 +149,7 @@ class Dart2JSTarget extends Target {
@override
Future
<
void
>
build
(
Environment
environment
)
async
{
final
String
dart2jsOptimization
=
environment
.
defines
[
kDart2jsOptimization
];
final
bool
csp
=
environment
.
defines
[
kCspMode
]
==
'true'
;
final
BuildMode
buildMode
=
getBuildModeForName
(
environment
.
defines
[
kBuildMode
]);
final
String
specPath
=
globals
.
fs
.
path
.
join
(
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
),
'libraries.json'
);
final
String
packageFile
=
FlutterProject
.
fromDirectory
(
environment
.
projectDir
).
hasBuilders
...
...
@@ -170,6 +174,8 @@ class Dart2JSTarget extends Target {
'-Ddart.vm.profile=true'
else
'-Ddart.vm.product=true'
,
if
(
csp
)
'--csp'
,
for
(
final
String
dartDefine
in
parseDartDefines
(
environment
))
'-D
$dartDefine
'
,
environment
.
buildDir
.
childFile
(
'main.dart'
).
path
,
...
...
packages/flutter_tools/lib/src/commands/build_web.dart
View file @
bf6c4c4a
...
...
@@ -25,6 +25,12 @@ class BuildWebCommand extends BuildSubCommand {
hide:
true
,
help:
'Whether to automatically invoke webOnlyInitializePlatform.'
,
);
argParser
.
addFlag
(
'csp'
,
defaultsTo:
false
,
negatable:
false
,
help:
'Disable dynamic generation of code in the generated output.'
'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).'
);
}
@override
...
...
@@ -59,6 +65,7 @@ class BuildWebCommand extends BuildSubCommand {
buildInfo
,
boolArg
(
'web-initialize-platform'
),
dartDefines
,
boolArg
(
'csp'
)
);
return
null
;
}
...
...
packages/flutter_tools/lib/src/web/compile.dart
View file @
bf6c4c4a
...
...
@@ -28,6 +28,7 @@ Future<void> buildWeb(
BuildInfo
buildInfo
,
bool
initializePlatform
,
List
<
String
>
dartDefines
,
bool
csp
,
)
async
{
if
(!
flutterProject
.
web
.
existsSync
())
{
throwToolExit
(
'Missing index.html.'
);
...
...
@@ -50,6 +51,7 @@ Future<void> buildWeb(
kInitializePlatform:
initializePlatform
.
toString
(),
kHasWebPlugins:
hasWebPlugins
.
toString
(),
kDartDefines:
jsonEncode
(
dartDefines
),
kCspMode:
csp
.
toString
(),
},
));
if
(!
result
.
success
)
{
...
...
packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
View file @
bf6c4c4a
...
...
@@ -59,6 +59,7 @@ void main() {
BuildInfo
.
debug
,
false
,
const
<
String
>[],
false
,
),
throwsA
(
isInstanceOf
<
ToolExit
>()));
}));
...
...
packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
View file @
bf6c4c4a
...
...
@@ -165,6 +165,33 @@ void main() {
expect
(
generated
,
contains
(
'entrypoint.main();'
));
}));
test
(
'Dart2JSTarget calls dart2js with expected args with csp'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'profile'
;
environment
.
defines
[
kCspMode
]
=
'true'
;
when
(
globals
.
processManager
.
run
(
any
)).
thenAnswer
((
Invocation
invocation
)
async
{
return
FakeProcessResult
(
exitCode:
0
);
});
await
const
Dart2JSTarget
().
build
(
environment
);
final
List
<
String
>
expected
=
<
String
>[
globals
.
fs
.
path
.
join
(
'bin'
,
'cache'
,
'dart-sdk'
,
'bin'
,
'dart'
),
globals
.
fs
.
path
.
join
(
'bin'
,
'cache'
,
'dart-sdk'
,
'bin'
,
'snapshots'
,
'dart2js.dart.snapshot'
),
'--libraries-spec='
+
globals
.
fs
.
path
.
join
(
'bin'
,
'cache'
,
'flutter_web_sdk'
,
'libraries.json'
),
'-O4'
,
// highest optimizations
'--no-minify'
,
// but uses unminified names for debugging
'-o'
,
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
absolute
.
path
,
'--packages=
${globals.fs.path.join('foo', '.packages')}
'
,
'-Ddart.vm.profile=true'
,
'--csp'
,
environment
.
buildDir
.
childFile
(
'main.dart'
).
absolute
.
path
,
];
verify
(
globals
.
processManager
.
run
(
expected
)).
called
(
1
);
},
overrides:
<
Type
,
Generator
>{
ProcessManager:
()
=>
MockProcessManager
(),
}));
test
(
'Dart2JSTarget calls dart2js with expected args in profile mode'
,
()
=>
testbed
.
run
(()
async
{
environment
.
defines
[
kBuildMode
]
=
'profile'
;
when
(
globals
.
processManager
.
run
(
any
)).
thenAnswer
((
Invocation
invocation
)
async
{
...
...
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